feat: add shell completion command for bash, zsh, and fish#168
feat: add shell completion command for bash, zsh, and fish#168404-Page-Found wants to merge 23 commits into
Conversation
Add \commit-echo completion\ subcommand that generates shell completion scripts for bash, zsh, and fish shells. Running without arguments prints a help message showing available shells and usage examples. Closes #67
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds a ChangesShell completion command
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/commands/completion.ts`:
- Around line 22-29: The subcommand detection in completion logic is using
COMP_WORDS[1] directly, so leading global flags are mistaken for the command and
subcommand completion never reaches the case branch for actual commands. Update
the completion flow in the completion script to scan COMP_WORDS for the first
non-option token before assigning subcmd, then use that value in the existing
case handling so completions like suggest and history work after flags such as
--no-color.
- Around line 173-176: The fish completion logic for the completion subcommand
is incomplete: __commit_echo_complete_options() only emits --help for
completion, so shell names are never suggested. Update the completion handling
in completion.ts so that when the current command is completion it also returns
bash, zsh, and fish as available options, and ensure the fallback does not
continue surfacing top-level subcommands for this case.
🪄 Autofix (Beta)
✅ Autofix completed
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 6b6359b2-7c08-4996-a4f6-0e19cf0a76f8
📒 Files selected for processing (3)
src/commands/completion.tssrc/index.tstests/completion-command.test.mjs
📜 Review details
🧰 Additional context used
📓 Path-based instructions (2)
src/commands/**/*
📄 CodeRabbit inference engine (AGENTS.md)
Organize command implementations in
src/commands/directory
Files:
src/commands/completion.ts
src/index.ts
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript for CLI entry point implementation in
src/index.ts
Files:
src/index.ts
🔇 Additional comments (3)
src/index.ts (1)
13-13: LGTM!Also applies to: 50-50, 119-126
tests/completion-command.test.mjs (1)
1-109: LGTM!src/commands/completion.ts (1)
97-133: 🎯 Functional CorrectnessDispatch on the subcommand from
_arguments -C
Thesuggest|history|batch|init|completioncases need to branch on the parsed subcommand, not the current shell command name.
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. Fixes Applied SuccessfullyFixed 1 file(s) based on 2 unresolved review comments. Files modified:
Commit: The changes have been pushed to the Time taken: |
Fixed 1 file(s) based on 2 unresolved review comments. Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
|
@coderabbitai full review |
✅ Action performedFull review finished. |
|
@coderabbitai full review |
✅ Action performedFull review finished. |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/commands/completion.ts`:
- Around line 17-19: The completion logic in completion.ts returns global flags
too early, so subcommand-specific options are never considered for commands like
suggest and completion. Update the completion flow in the script generation
logic to determine the active subcmd before the `if [[ "${cur}" == -* ]]`
branch, then build the option list by merging `global_opts` with the matching
subcommand option set before assigning COMPREPLY.
- Around line 107-140: The zsh dispatcher in completion generation is checking
the executable name instead of the subcommand, so the
suggest/history/batch/init/completion cases never match. Update the dispatcher
in completion.ts to branch on the first argument (or otherwise derive the active
subcommand) so the _arguments definitions for those subcommands and the
bash|zsh|fish choices are reached correctly.
- Around line 154-156: The fish completion path is still selecting the second
token as the subcommand, which breaks cases where options appear before the real
command. Update the fish branch in completion dispatch to derive the first
non-option token from commandline output, matching the bash parsing behavior
used elsewhere, and use that value for the switch instead of $cmd[2].
🪄 Autofix (Beta)
✅ Autofix completed
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 5abc0206-d6e2-48b1-abbc-ff9a8df13fe5
📒 Files selected for processing (3)
src/commands/completion.tssrc/index.tstests/completion-command.test.mjs
📜 Review details
🧰 Additional context used
📓 Path-based instructions (2)
src/index.ts
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript for CLI entry point implementation in
src/index.ts
Files:
src/index.ts
src/commands/**/*
📄 CodeRabbit inference engine (AGENTS.md)
Organize command implementations in
src/commands/directory
Files:
src/commands/completion.ts
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. Fixes Applied SuccessfullyFixed 1 file(s) based on 3 unresolved review comments. Files modified:
Commit: The changes have been pushed to the Time taken: |
Fixed 1 file(s) based on 3 unresolved review comments. Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
|
@coderabbitai full review |
✅ Action performedFull review finished. |
|
@coderabbitai full review |
✅ Action performedFull review finished. |
|
@coderabbitai full review |
✅ Action performedFull review finished. |
|
@coderabbitai full review |
✅ Action performedFull review finished. |
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
src/commands/completion.ts (1)
17-20: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winResolve the active bash subcommand before returning flag completions.
Line 17 exits on any
-*token, socommit-echo suggest --<TAB>andcommit-echo completion --<TAB>never reach the subcommand-specific option sets. Determinesubcmdfirst, then mergeglobal_optswith the active subcommand options before buildingCOMPREPLY.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/commands/completion.ts` around lines 17 - 20, The bash completion logic is returning too early for any flag-like token, so active subcommand options are never considered. Update the completion flow in the completion script to resolve subcmd before handling "-" prefixed input, then combine global_opts with the current subcommand’s option set before populating COMPREPLY. Keep the early return only after the merged option list has been used so subcommand-specific completions work for commit-echo suggest and commit-echo completion.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/commands/completion.ts`:
- Around line 107-140: The zsh completion dispatch in completion.ts is still
using a fixed position ($words[2]), so leading global flags cause the subcommand
detection to miss branches like completion. Update the shell-case logic to
derive the first non-option argument from the words array before the case
statement, and keep the existing suggest/history/batch/init/completion handling
keyed off that resolved subcommand symbol.
---
Duplicate comments:
In `@src/commands/completion.ts`:
- Around line 17-20: The bash completion logic is returning too early for any
flag-like token, so active subcommand options are never considered. Update the
completion flow in the completion script to resolve subcmd before handling "-"
prefixed input, then combine global_opts with the current subcommand’s option
set before populating COMPREPLY. Keep the early return only after the merged
option list has been used so subcommand-specific completions work for
commit-echo suggest and commit-echo completion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: b7fd8d37-930a-4751-9ef7-6aeed9f90134
📒 Files selected for processing (3)
src/commands/completion.tssrc/index.tstests/completion-command.test.mjs
📜 Review details
🧰 Additional context used
📓 Path-based instructions (2)
src/index.ts
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript for CLI entry point implementation in
src/index.ts
Files:
src/index.ts
src/commands/**/*
📄 CodeRabbit inference engine (AGENTS.md)
Organize command implementations in
src/commands/directory
Files:
src/commands/completion.ts
🔇 Additional comments (2)
src/index.ts (1)
13-13: LGTM!Also applies to: 50-50, 119-126
tests/completion-command.test.mjs (1)
1-110: LGTM!
In bash, move subcmd resolution before the flag check so that subcommand-specific options (e.g. suggest --stream) are offered after the subcommand is typed, instead of only returning global opts. In zsh, replace the fixed [2] lookup with a loop that finds the first non-option argument, so leading global flags like --yes don't break subcommand option dispatch.
|
@coderabbitai full review |
✅ Action performedFull review finished. |
|
@coderabbitai full review |
✅ Action performedFull review finished. |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/commands/completion.ts`:
- Around line 77-84: The zsh completion command list in completion.ts is missing
the top-level help subcommand, causing an inconsistent set of suggestions
compared with the bash and fish completion generators. Update the commands array
used by the zsh completion script to include help alongside init, config,
suggest, history, batch, and completion so commit-echo tab completion advertises
the same commands across shells.
- Around line 167-176: The fish completion generation in completion.ts is using
the wrong printf shape: each entry already includes option and description
separated by a tab, so the format string should emit one string per line instead
of pairing adjacent arguments. Update the fish completion printf blocks in the
completion generation logic, including the block that emits --commit through
--help and the other repeated blocks later in the file, by changing the format
to match the single tab-delimited entries so Fish parses each
candidate/description correctly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 4f75384b-5f04-4c10-b4b9-25b8d472ae79
📒 Files selected for processing (3)
src/commands/completion.tssrc/index.tstests/completion-command.test.mjs
📜 Review details
🧰 Additional context used
📓 Path-based instructions (2)
tests/**/*.mjs
📄 CodeRabbit inference engine (AGENTS.md)
tests/**/*.mjs: Use Node.js built-innode:test(not Jest or Mocha) for test files undertests/.
Some tests may skip on Windows when platform-specific mock logic is involved.
Files:
tests/completion-command.test.mjs
src/**/*.ts
📄 CodeRabbit inference engine (AGENTS.md)
Use
.jsextensions for all local imports in ESM TypeScript source files, and useimport typefor type-only imports.
Files:
src/commands/completion.tssrc/index.ts
| commands=( | ||
| 'init:Run interactive setup wizard' | ||
| 'config:View current configuration' | ||
| 'suggest:Generate commit suggestions' | ||
| 'history:View learned style profile and recent commit history' | ||
| 'batch:Process multiple git repositories in batch mode' | ||
| 'completion:Generate shell completion scripts' | ||
| ) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Zsh omits the help subcommand from top-level completions.
Bash and fish both advertise help, but the zsh commands list stops at completion, so commit-echo <TAB> exposes a different command set on zsh than on the other supported shells.
Suggested fix
commands=(
'init:Run interactive setup wizard'
'config:View current configuration'
'suggest:Generate commit suggestions'
'history:View learned style profile and recent commit history'
'batch:Process multiple git repositories in batch mode'
'completion:Generate shell completion scripts'
+ 'help:Display help'
)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| commands=( | |
| 'init:Run interactive setup wizard' | |
| 'config:View current configuration' | |
| 'suggest:Generate commit suggestions' | |
| 'history:View learned style profile and recent commit history' | |
| 'batch:Process multiple git repositories in batch mode' | |
| 'completion:Generate shell completion scripts' | |
| ) | |
| commands=( | |
| 'init:Run interactive setup wizard' | |
| 'config:View current configuration' | |
| 'suggest:Generate commit suggestions' | |
| 'history:View learned style profile and recent commit history' | |
| 'batch:Process multiple git repositories in batch mode' | |
| 'completion:Generate shell completion scripts' | |
| 'help:Display help' | |
| ) |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/commands/completion.ts` around lines 77 - 84, The zsh completion command
list in completion.ts is missing the top-level help subcommand, causing an
inconsistent set of suggestions compared with the bash and fish completion
generators. Update the commands array used by the zsh completion script to
include help alongside init, config, suggest, history, batch, and completion so
commit-echo tab completion advertises the same commands across shells.
| printf '%s\\t%s\\n' \\ | ||
| '--commit\\tCommit the selected suggestion' \\ | ||
| '--yes\\tAutomatically select the first suggestion' \\ | ||
| '--verbose\\tPrint diagnostic information' \\ | ||
| '--model\\tOverride the configured LLM model' \\ | ||
| '--stream\\tStream suggestions as they are generated' \\ | ||
| '--dry-run\\tShow the LLM input without generating suggestions' \\ | ||
| '--no-commit\\tDeprecated alias' \\ | ||
| '--auto\\tAlias for --yes' \\ | ||
| '--help\\tDisplay help' |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Fish completion entries are emitted with the wrong printf shape.
These arguments already contain option<TAB>description, but the format string still expects two %s values. Fish will pair adjacent entries onto one line, so the generated script does not expose valid candidates/descriptions. The same bug repeats in the later printf blocks on Lines 178-196, 201-208, and 231-236.
Suggested fix
- printf '%s\t%s\n' \
+ printf '%s\n' \
'--commit\tCommit the selected suggestion' \
'--yes\tAutomatically select the first suggestion' \
'--verbose\tPrint diagnostic information' \Apply the same format-string change to the other fish completion printf blocks in this file.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/commands/completion.ts` around lines 167 - 176, The fish completion
generation in completion.ts is using the wrong printf shape: each entry already
includes option and description separated by a tab, so the format string should
emit one string per line instead of pairing adjacent arguments. Update the fish
completion printf blocks in the completion generation logic, including the block
that emits --commit through --help and the other repeated blocks later in the
file, by changing the format to match the single tab-delimited entries so Fish
parses each candidate/description correctly.
|
@coderabbitai full review |
✅ Action performedFull review finished. |
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| Security | 1 critical |
🟢 Metrics 29 complexity · 0 duplication
Metric Results Complexity 29 Duplication 0
AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Pull Request Overview
The PR introduces shell completion for Bash, Zsh, and Fish. While the core functionality is present, the Zsh implementation is currently broken due to a syntax error (_compdef) and incorrect subcommand detection logic. Additionally, the Fish script provides redundant suggestions after a subcommand is already selected.
Codacy results are not up to standards due to a potential ReDoS vulnerability in the tests. These functional and security issues should be addressed before merging.
About this PR
- The Zsh completion implementation is significantly more fragile than the Bash and Fish versions. It currently omits the 'help' subcommand and contains logic that fails if global options are provided before a subcommand. A more robust approach for Zsh is required to ensure parity with the other supported shells.
Test suggestions
- Found recommended test scenario: Running 'completion' without arguments prints help and usage examples
- Found recommended test scenario: Generating Bash script outputs valid 'complete -F' logic with subcommands
- Found recommended test scenario: Generating Zsh script outputs valid '#compdef' logic with subcommands
- Found recommended test scenario: Generating Fish script outputs valid 'complete -c' logic with helper functions
- Found recommended test scenario: Passing an unsupported shell name (e.g., 'powershell') returns error and exit code 1
- Found recommended test scenario: Shell name input is case-insensitive
- Found recommended test scenario: Zsh script includes correct subcommand-specific options (e.g., --commit for suggest)
TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback
| esac | ||
| } | ||
|
|
||
| _compdef _commit_echo commit-echo |
There was a problem hiding this comment.
🔴 HIGH RISK
The command _compdef is a typo and will cause the script to fail when sourced. The correct Zsh command for associating a completion function is compdef.
| _compdef _commit_echo commit-echo | |
| compdef _commit_echo commit-echo |
| _describe 'command' commands | ||
| ;; | ||
| args) | ||
| case \$words[2] in |
There was a problem hiding this comment.
🔴 HIGH RISK
Subcommand detection in Zsh is currently incorrect. Using *:: in _arguments shifts the words array so that the subcommand is at index 1. Furthermore, using a hardcoded index is fragile if global flags (e.g., --no-color) are passed before the subcommand.
| case \$words[2] in | |
| case \$words[1] in |
Consider a loop or checking line[1] via _arguments for a more robust implementation.
| const { stdout } = await runCompletion(['bash']); | ||
| const expectedSubcommands = ['init', 'config', 'suggest', 'history', 'batch', 'completion']; | ||
| for (const subcmd of expectedSubcommands) { | ||
| assert.match(stdout, new RegExp(subcmd)); |
There was a problem hiding this comment.
🟡 MEDIUM RISK
The use of the RegExp constructor with a non-literal value is flagged as a security risk (ReDoS). Since this is a simple substring check in a test, use includes() for better performance and safety.
| assert.match(stdout, new RegExp(subcmd)); | |
| assert.ok(stdout.includes(subcmd), `Expected stdout to contain subcommand: ${subcmd}`); |
| end | ||
|
|
||
| # Otherwise, suggest subcommands | ||
| __commit_echo_subcommands |
There was a problem hiding this comment.
🟡 MEDIUM RISK
In the Fish completion script, subcommands are suggested even when one has already been specified. Only suggest subcommands if no subcommand has been identified yet.
Wrap the call to __commit_echo_subcommands at the end of the __commit_echo_completions function in an if test -z "$subcmd" block.
| 'completion:Generate shell completion scripts' | ||
| ) |
There was a problem hiding this comment.
⚪ LOW RISK
Suggestion: Add 'help:Display help' to the commands array in the Zsh completion script. The 'help' subcommand is included in the Bash and Fish versions but is missing here, which leads to inconsistent behavior across shells.
There was a problem hiding this comment.
Pull Request Overview
The PR introduces a necessary completion command but currently fails to meet several quality and functional standards. Codacy analysis indicates the changes are not up to standards, primarily due to potential security risks in the test suite and logic errors in the generated shell scripts.
Several critical logic flaws were identified in the Zsh and Fish script generation that will prevent subcommands and options from being correctly suggested. Additionally, the implementation is inconsistent across shells; for instance, the help subcommand is omitted only in the Zsh implementation. High-priority issues include a misspelled registration command (_compdef) and a logic error in Zsh word-shifting that breaks subcommand-specific completion.
About this PR
- There is a lack of parity between the three shell implementations. Specifically, Bash and Fish include the 'help' subcommand while Zsh does not. Furthermore, none of the scripts currently include short-form flags or aliases defined in the main CLI entry point, which contradicts the requirement for comprehensive flag support.
Test suggestions
- Display help message when the completion command is invoked without a shell argument
- Verify Bash completion script generation contains correct subcommands and global options
- Verify Zsh completion script generation contains correct subcommands and specific options
- Verify Fish completion script generation contains correct subcommands and global options
- Ensure shell argument matching is case-insensitive (e.g., 'FISH' or 'BASH')
- Verify non-zero exit code and error output for unsupported shell arguments (e.g., 'powershell')
TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback
| for w in \$words[2,-1]; do | ||
| case \$w in | ||
| -*) ;; | ||
| *) subcmd=\$w; break ;; | ||
| esac | ||
| done |
There was a problem hiding this comment.
🔴 HIGH RISK
Subcommand detection in Zsh fails because the shifting behavior of *:: is not accounted for. Since the subcommand is now at $words[1], the loop starting at $words[2] skips it. This prevents any subcommand-specific options (like --model for suggest) from being completed.
| _compdef _commit_echo commit-echo | ||
| `; |
There was a problem hiding this comment.
🔴 HIGH RISK
The registration command uses _compdef, but the standard Zsh command is compdef. Using the underscored version (which is typically an internal function name) will result in a 'command not found' error when the script is sourced directly by a user.
| end | ||
|
|
||
| # Otherwise, suggest subcommands | ||
| __commit_echo_subcommands |
There was a problem hiding this comment.
🟡 MEDIUM RISK
The script suggests all subcommands even when one has already been selected. It should only suggest subcommands if the $subcmd variable is empty to avoid polluting the suggestion list with redundant commands.
| const { stdout } = await runCompletion(['bash']); | ||
| const expectedSubcommands = ['init', 'config', 'suggest', 'history', 'batch', 'completion']; | ||
| for (const subcmd of expectedSubcommands) { | ||
| assert.match(stdout, new RegExp(subcmd)); |
There was a problem hiding this comment.
🟡 MEDIUM RISK
Suggestion: Avoid using the RegExp constructor with variables to prevent Potential Regular Expression Denial of Service (ReDoS) risks. Since you are checking for simple substring existence in the test output, use stdout.includes(subcmd) for better security and readability.
| assert.match(stdout, new RegExp(subcmd)); | |
| assert.ok(stdout.includes(subcmd)); |
| commands="init config suggest history batch completion help" | ||
|
|
||
| # Global options | ||
| global_opts="--yes --auto --no-color --help --version" |
There was a problem hiding this comment.
🟡 MEDIUM RISK
Suggestion: The completion scripts are missing several short-form flags (e.g., -y, -v, -m, -n) and long-form aliases (e.g., --auto) defined in the CLI. Please synchronize the scripts with the definitions in src/index.ts to ensure all valid options are suggested to the user.
…on-command # Conflicts: # AGENTS.md
- Fish completion: fix printf format from '%s\t%s\n' to '%s\n' since entries already contain embedded tab-separated option/description pairs - Zsh completion: fix '_compdef' typo to 'compdef' (underscore variant is internal and causes command-not-found when sourced by users) - Zsh completion: add missing 'help' subcommand to commands array for parity with bash and fish scripts - Zsh completion: fix subcommand detection by starting word scan at \[1,-1] instead of \[2,-1] since '*::args:->args' shifts the words array so the subcommand is at index 1 - Fish completion: guard subcommand list fallthrough so subcommands are not re-suggested after one has already been selected - Tests: replace new RegExp(subcmd) with stdout.includes(subcmd) for safer string matching without ReDoS concern
…gistry Replaces three hand-maintained shell script template literals with three small generator functions fed by a single SUBCOMMANDS data structure (plus a parallel GLOBAL_OPTIONS array). Adding a subcommand or option now only requires editing one place. Also fixes two bugs found in PR review: - Bash completion no longer suggests option flags immediately after a value-taking flag like `--model`. The list of value-taking flags is auto-derived from each option's `value` field. - Error output from an unsupported shell no longer emits ANSI red when the user passes `--no-color` or has `NO_COLOR` set in the environment. The new `shouldUseColor()` helper also feeds the help printer. Tests: 14 -> 20. New cases cover `--help` on the subcommand, value-flag guards for all three shells, `--no-color` in the error path, and a `bash -n` syntax check on the generated bash script.
Three behavioral fixes in the generated completion scripts plus added
zsh and fish syntax validation tests.
- Remove the synthetic 'help' subcommand from the bash, zsh, and fish
completion lists. The CLI does not register a help subcommand, so
tab-completing 'commit-echo help' would fall through to the default
action and run suggestCommand({ commit: true }), which is a footgun.
- Replace the bash extglob value-flag guard (@(valueFlag)) with a
portable case statement. The extglob form required 'shopt -s extglob'
to be in effect in the user's shell; the case form is POSIX-clean
and works regardless of extglob state.
- Add a JSDoc comment on the SUBCOMMANDS registry explaining that the
'hook' subcommand is intentionally omitted because it is registered
as hidden (it is invoked by Git, not humans).
Tests:
- Update the bash extglob regex to match the new case form.
- Add 'completion zsh script is syntactically valid zsh' and
'completion fish script is syntactically valid fish' tests, gated on
the corresponding shell being installed on the test host.
All 22 completion tests pass; full suite (231 tests) green.
The shouldUseColor helper previously required NO_COLOR to be a non-empty string, but the no-color.org specification states that any form of the variable (including an explicitly empty value) should disable color. Drop the empty-string check so the spec is followed literally. Also rename the misleading 'programArgs' parameter to 'argv' and add short comments explaining the zsh two-state completion machine so future maintainers can follow the command/args dispatch at a glance. Pin the new behavior with a regression test.
Five small follow-up fixes and one docs tweak for the completion command, all driven by PR #168 review feedback. Behavior changes: - Advertise short flag aliases in completion. The CLI accepts `-y`/`-v`/`-m`/`-n`/`-r` on the suggest and batch subcommands, but tab-completion was only suggesting the long forms. The `SubcommandOption` interface now has an optional `short` field, the registry carries the short aliases that match `index.ts`, and all three shell generators emit both forms. - Handle the glued `--flag=value` form for value-taking flags in both bash and fish completion. Typing `commit-echo suggest --model=gpt<TAB>` no longer tries to complete the value. Zsh's `_arguments` already handled the glued form, so no change was needed there. - Update the bash install example in the help text. The previous example appended to `~/.bashrc`, which works but is unconventional. The help now shows both a system-wide path (`/etc/bash_completion.d/commit-echo`) and a per-user path (`~/.local/share/bash-completion/completions/commit-echo`). Code quality: - Add an `isSupportedShell(s: string): s is SupportedShell` type guard in place of the `VALID_SHELLS.includes(x) as SupportedShell` cast in `completionCommand`. - Hoist the test file's inline `await import(...)` calls to a single set of top-of-file imports and a shared `execFilePromisified` helper. Tests: - Expand "completion zsh script includes suggest subcommand options" to assert all nine registered suggest options are present, not just `--commit`/`--stream`/`--dry-run`/`--verbose`. - Add `completion bash script includes short flag aliases`, `completion zsh script includes short flag aliases`, and `completion fish script includes short flag aliases` tests. - Add `completion bash script handles --flag=value glued form`. - Update `completion fish script guards value-taking flags like --model` to match the new `case` shape (long + short + glued forms). 23 -> 27 completion tests; full suite 234 -> 237 (1 pre-existing Windows-only skip).
…subcmd scan Zsh _arguments specs for short options incorrectly used ':--yes' suffix, making zsh treat boolean flags like -y as value-taking. Remove the spurious value marker for boolean short options and keep ':model:' only for flags that actually take a value like -m. Refactor fish __commit_echo_complete_options to accept the subcommand as a parameter instead of re-scanning commandline tokens, eliminating duplicated logic between it and __commit_echo_completions.
Commander auto-generates a \help\ subcommand, but it was absent from the SUBCOMMANDS array so bash, zsh, and fish completions would not suggest it. Add the entry and update the three subcommand-list tests.
Fish printf requires double-quoted format strings and arguments to interpret escape sequences like \t (tab) and \n (newline). Single quotes produced literal backslash-t characters instead of actual tab separators in completion suggestions.
The 'case completion' block inside __commit_echo_complete_options was missing its closing 'end', leaving the switch statement unclosed and producing an invalid fish completion script.
… specs The zsh _arguments spec for global short options used ':--yes' suffix, making zsh treat boolean flags like -y as value-taking. Remove the spurious value marker for boolean options and use stdout.includes() instead of new RegExp() in the corresponding test.
Parse every subcommand's --help output and verify all flags appear in the generated bash, zsh, and fish completion scripts. Catches cases where a new option is added to src/index.ts but not reflected in the SUBCOMMANDS array in completion.ts. Also adds a sync requirement comment documenting the coupling.
…ead of hardcoding Remove special-cased completion subcommand blocks from zsh and fish generators. Options now come from the SUBCOMMANDS array like every other subcommand, with the positional shell argument appended conditionally. Add SHELL_NAMES_LIST constant derived from VALID_SHELLS to eliminate hardcoded 'bash zsh fish' strings across all three generators. Fix trailing backslash on last zsh global option spec.
…ommand in fish Restructure the fish completion dispatch to check for empty subcommand before the flag-match block. Previously, typing a flag like --y before selecting a subcommand would fall through to suggest subcommands instead of global options. Now matches the bash script's behavior. Also adds docstrings to the three shell generator functions and a test for the fish edge case.
…ion lines The fish generator embedded a trailing backslash inside double-quoted string literals for continuation lines. In fish, this escapes the closing quote, making the literal string value include a backslash character (e.g. completion suggestions displayed as 'init\'). Add a joinContinuationLines helper that appends ' \' only to interior lines, leaving the last line clean. Also add a fish-specific test for suggest subcommand options to match the existing zsh test coverage.
…dd shell name tests Skip the zsh _arguments call for subcommands with no options (like help) to avoid a dangling backslash continuation. Add tests verifying shell name suggestions work for the completion subcommand across all three shells, and that zsh omits _arguments for the help case.
Summary
Add \commit-echo completion\ subcommand that generates shell completion scripts for bash, zsh, and fish shells. Running without arguments prints a help message showing available shells and usage examples.
What changed
Motivation
Provides tab-completion for users who want faster CLI interaction without remembering subcommand names and flags. Referenced in #67.
Testing
pm run build\ passes with no errors
Closes #67
Summary by CodeRabbit
completionCLI command to generate shell autocompletion scripts for bash, zsh, and fish.completionusage.