feat(completions): add bash, zsh, and fish shell completions for mgw CLI#167
Conversation
…or mgw CLI Adds completions/ directory with hand-authored completion scripts for all three major shells. Also adds bin/generate-completions.cjs which generates the same scripts programmatically from a single source-of-truth definitions object, keeping completions in sync as commands and flags evolve. Covers all 12 subcommands (run, init, project, milestone, next, issue, update, pr, sync, issues, link, help) and all global flags plus per-command flags (--quiet, --auto, --interactive, --base, --label, --milestone, --assignee, --state, --search, --limit). Closes #123 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
snipcodeit
left a comment
There was a problem hiding this comment.
Review: PR #167 — bash, zsh, and fish shell completions
The generator approach is the right design — single source-of-truth prevents drift. There are two blocking issues before this is ready to ship.
🔴 completions/ not in package.json files array
package.json has:
"files": ["dist/", "bin/mgw-install.cjs", "commands/", "templates/"]completions/ is not listed. When the package is published to npm, the completion scripts will not be included. The init completion installer (PR #168) references require.resolve("mgw/package.json") to locate the completions directory — but if the completions are not in the published package, that lookup will fail for all npm-installed users.
Fix: add "completions/" to the files array in package.json.
🔴 Generated completion files not committed
The diff shows bin/generate-completions.cjs but the actual generated files (completions/mgw.bash, completions/mgw.zsh, completions/mgw.fish) do not appear in the diff. Are they committed to the branch? If not, the completions/ directory will be empty when the PR is merged, making the shell completion feature non-functional.
Run node bin/generate-completions.cjs and commit the output files.
🟡 No npm run completions script
There is no npm script to regenerate completions. Add to package.json:
"completions": "node bin/generate-completions.cjs"This makes it easy for contributors to regenerate after adding commands. Could also add it to the build script.
🟡 Hardcoded model names may go stale
The bash/zsh completions offer claude-opus-4-5 claude-sonnet-4-5 claude-haiku-4-5 as model hints. The actual model IDs use versioned suffixes (e.g. claude-haiku-4-5-20251001). Using the shorter alias names for completion is fine — but document that these are display hints, not validated model IDs. If mgw already has a --model validation path, ensure it accepts both forms.
🟡 Bash completion uses _init_completion from bash-completion v2
_init_completion is provided by the bash-completion package (v2+). On macOS default bash (3.x) or systems without bash-completion installed, the function will be undefined and the completion will silently fail. Consider adding a fallback:
_init_completion 2>/dev/null || {
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
}✅ Good points
- Generator pattern is the right architecture — completions stay in sync with commands
- All 12 subcommands covered
- Per-command flags correctly scoped (not all flags shown for all commands)
__fish_use_subcommand/__fish_seen_subcommand_fromguards are correct fish idioms--state,--assignee,--modelget value hint completions — exactly right- Fish completions auto-load from
~/.config/fish/completions/— no activation needed
… fallback - Add completions/ to package.json files array so scripts are published to npm - Add completions npm script: node bin/generate-completions.cjs - Fix _mgw bash completion to use _init_completion 2>/dev/null fallback for environments without bash-completion v2; manually sets COMPREPLY/cur/prev - Update generator to emit the same fallback pattern for future regeneration
Summary
completions/mgw.bash,completions/mgw.zsh, andcompletions/mgw.fish— hand-authored completion scripts covering all 12 subcommands and their flagsbin/generate-completions.cjs— a programmatic generator that rebuilds all three scripts from a single command-definition object, keeping completions in sync as the CLI evolves_mgw()+complete -F; zsh uses#compdef mgwwith_arguments; fish usescomplete -c mgwdirectives--dry-run,--json,--verbose,--debug,--model) are wired to all subcommands; per-command flags handled individuallyCloses #123
Milestone Context
Changes
completions/
completions/mgw.bash— bash completion via_mgw()function withcomplete -F _mgw mgw; covers all subcommands, per-command flags, and--state/--assignee/--modelvalue hintscompletions/mgw.zsh— zsh completion via#compdef mgw; uses_arguments -Cwith subcommand dispatch,_mgw_subcommandshelper, and_mgw_issue_numbersthat reads.mgw/active/*.jsonfor live issue completioncompletions/mgw.fish— fish completion usingcomplete -c mgwdirectives with__fish_use_subcommandand__fish_seen_subcommand_fromguards; includes choice lists for--state,--limit,--assigneebin/
bin/generate-completions.cjs— Node.js generator script; definesCOMMANDSandGLOBAL_FLAGSarrays as source-of-truth; exposesgenerateBash(),generateZsh(),generateFish()functions; CLI usage:node bin/generate-completions.cjs [--out-dir <dir>]Test Plan
source completions/mgw.bashthenmgw <TAB>shows all 12 subcommandsmgw run <TAB>shows--quiet,--auto, and global flagsmgw issues --state <TAB>showsopen closed allcompletions/mgw.zshto$fpath, runcompinit, verifymgw <TAB>and subcommand flag completioncompletions/mgw.fishto~/.config/fish/completions/, verifymgw <TAB>and per-subcommand flag suggestionsnode bin/generate-completions.cjsregenerates all three files intocompletions/without errorsnode bin/generate-completions.cjs --out-dir /tmp/testwrites to custom output directory