Add --install flag to completions command that outputs an install script

This commit is contained in:
Chris Wanstrath 2026-02-21 08:26:44 -08:00
parent 12ba2c7c82
commit 4db29e4beb
2 changed files with 15 additions and 2 deletions

View File

@ -161,8 +161,9 @@ registerVmCommands(program)
program program
.command("completions") .command("completions")
.option("--install", "Output a shell script that installs the completions file")
.description("Output fish shell completions") .description("Output fish shell completions")
.action(() => completionsAction(program)) .action((opts: { install?: boolean }) => completionsAction(program, opts))
// ── Default: show list if sessions exist, otherwise help ───────────── // ── Default: show list if sessions exist, otherwise help ─────────────

View File

@ -1,7 +1,19 @@
import type { Command, Option } from "commander" import type { Command, Option } from "commander"
/** Generate fish completions dynamically from the Commander program tree. */ /** 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[] = [ const lines: string[] = [
"# Fish completions for sandlot (auto-generated)", "# Fish completions for sandlot (auto-generated)",
"# Install: sandlot completions > ~/.config/fish/completions/sandlot.fish", "# Install: sandlot completions > ~/.config/fish/completions/sandlot.fish",