From 4db29e4beb611182429d8a36ec1543fc8e1415cf Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Sat, 21 Feb 2026 08:26:44 -0800 Subject: [PATCH] Add `--install` flag to completions command that outputs an install script --- src/cli.ts | 3 ++- src/commands/completions.ts | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index 4bcc5a5..55242dc 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -161,8 +161,9 @@ registerVmCommands(program) program .command("completions") + .option("--install", "Output a shell script that installs the completions file") .description("Output fish shell completions") - .action(() => completionsAction(program)) + .action((opts: { install?: boolean }) => completionsAction(program, opts)) // ── Default: show list if sessions exist, otherwise help ───────────── diff --git a/src/commands/completions.ts b/src/commands/completions.ts index c597be7..39b2888 100644 --- a/src/commands/completions.ts +++ b/src/commands/completions.ts @@ -1,7 +1,19 @@ import type { Command, Option } from "commander" /** Generate fish completions dynamically from the Commander program tree. */ -export function action(program: Command) { +export function action(program: Command, opts: { install?: boolean } = {}) { + if (opts.install) { + const dest = "~/.config/fish/completions/sandlot.fish" + const lines = [ + "#!/bin/sh", + `mkdir -p ~/.config/fish/completions`, + `sandlot completions > ${dest}`, + `echo "Installed fish completions to ${dest}"`, + ] + process.stdout.write(lines.join("\n") + "\n") + return + } + const lines: string[] = [ "# Fish completions for sandlot (auto-generated)", "# Install: sandlot completions > ~/.config/fish/completions/sandlot.fish",