feat(complete): auto-completion for usage shebang scripts#620
Conversation
Adds `usage g completion-init <shell>` (bash/zsh/fish), a one-time init script users source from their shell rc to enable <Tab> completion for any command on $PATH whose first line is a `usage` shebang. No per-script `usage g completion` generation required. - bash: registers `complete -D` default handler that detects the shebang at completion time and dispatches to `usage complete-word`. Chains to `_completion_loader` for non-usage commands so bash-completion's dynamic loading still works. - zsh: registers `compdef -default-` fallback. Falls back to `_files` for non-usage commands. - fish: scans `$PATH` once at shell startup (no `-default-` equivalent exists) and registers `complete -c <name>` per usage shebang script. Closes the docs gap reported in #617 where users expected shebang scripts on $PATH to gain completion automatically. Tests: integration tests in shell_completions_integration.rs drive each shell against a staged usage shebang script. The `skip_if_shell_missing` helper now panics under CI=1 to prevent silent skips. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Reflects the bash/fish/zsh shell choices in the auto-generated reference docs, JSON, KDL spec, and Fig completion. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Greptile SummaryAdds Confidence Score: 5/5Safe to merge; only P2 style suggestions found. No P0 or P1 issues found. The implementation is well-structured: fish correctly caps reads and deduplicates, bash properly chains to prior handlers and guards against infinite recursion, and zsh's -default- fallback is correctly scoped. The two P2 findings (misleading docs heading and uncapped read -r in bash/zsh on-demand handlers) are minor quality issues that do not affect correctness. lib/src/complete/bash.rs and lib/src/complete/zsh.rs for the uncapped read -r in the shebang peek; docs/cli/completions.md for the misleading section heading. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["User presses Tab"] --> B{Shell}
B -->|bash| C["complete -D fires\n_usage_default_complete"]
B -->|zsh| D["compdef -default- fires\n_usage_default_complete"]
B -->|fish| E["complete -C fires\n(registered at startup)"]
C --> F{Read first line\nof cmdpath}
D --> F
E --> G["usage complete-word\n--shell fish -f file"]
F -->|"#!*usage*"| H["usage complete-word\n--shell bash/zsh -f file"]
F -->|not usage shebang| I{Fallback}
I -->|bash| J["_usage_chained_default_complete\nor _completion_loader"]
I -->|zsh| K["_files"]
H --> L["Candidates shown"]
G --> L
subgraph Fish startup
P["__usage_register_shebang_completions"] --> Q["for dir in PATH"]
Q --> R["read -n 128 first line"]
R -->|"#!*usage*"| S["complete -c name -x -a ..."]
end
Reviews (5): Last reviewed commit: "chore(ci): self-heal pwsh dependency in ..." | Re-trigger Greptile |
The shell completion integration tests now panic under CI=1 if the shell is missing rather than silently skipping. ubuntu-latest only ships bash, so install zsh and fish in the test, autofix, and coverage workflows. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #620 +/- ##
==========================================
- Coverage 79.03% 78.94% -0.10%
==========================================
Files 48 49 +1
Lines 7235 7284 +49
Branches 7235 7284 +49
==========================================
+ Hits 5718 5750 +32
- Misses 1140 1147 +7
- Partials 377 387 +10 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- fish: replace `path basename` (fish 3.5+) with `string replace -r` so the init works on Ubuntu 22.04 LTS (fish 3.3) and earlier. - fish: cap `read` at 128 chars so binary executables without a newline don't cause fish to buffer the entire file at startup. - bash: capture the pre-existing `complete -D` handler at registration time and chain to it for non-usage commands. Removes silent breakage when bash-completion's own default handler is registered before this init. - bash: tolerate `complete -p -D` exiting non-zero under `set -e` when no prior handler exists. - docs: drop the stale "only bash supported" info block — zsh and fish ship in the same PR. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Thanks for the review @greptile-apps. All four addressed in f3dd562:
One incidental fix: This comment was generated by Claude Code. |
|
All four fixes are confirmed in f3dd562 and implemented correctly:
The implementation looks clean and the snapshot tests will catch regressions. LGTM. ✅ Tip: You can customize Greptile's behavior for this repo with |
…error
Codecov flagged 90% patch coverage on the original PR; the gap was the
`complete_init` match arms and its UnsupportedShell error path. Adds two
unit tests:
- supported shells (bash/fish/zsh) all return non-empty output
- unsupported shell ("nu") returns UsageErr::UnsupportedShell
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Per Cursor Bugbot review on PR #620: the existing per-binary `complete_fish` detects `commandline -x` (fish 3.4+) and prefers `commandline -xpc` for accurate tokenization of quoted/complex arguments, falling back to `-opc` on older fish. The init script unconditionally used `-opc`, so init-registered completions were slightly less accurate than per-binary ones. Add the same detection at init time and embed the chosen `commandline` form into each `complete -c` registration. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 9e82ab4. Configure here.
Per Cursor Bugbot review on PR #620: the powershell integration test now panics under CI=1 if pwsh is missing, but the workflows didn't declare pwsh as an explicit dependency — they relied on it being pre-installed on the GitHub ubuntu-latest runner image. Add a guarded `snap install powershell --classic` to all three workflows that install shells (test, autofix, coverage). Common case: pwsh is already on the runner and the install step is a no-op. If a future runner image drops pwsh, CI self-heals instead of failing with a panic. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
### 🚀 Features - **(complete)** auto-completion for usage shebang scripts by [@jdx](https://github.com/jdx) in [#620](#620) ### 🐛 Bug Fixes - **(docs)** stack banner and pin close button on mobile by [@jdx](https://github.com/jdx) in [#603](#603) ### 📚 Documentation - **(site)** show release version and github stars by [@jdx](https://github.com/jdx) in [#604](#604) - add cross-site announcement banner by [@jdx](https://github.com/jdx) in [#600](#600) - fix banner dark-mode contrast by [@jdx](https://github.com/jdx) in [#601](#601) - respect banner expires field by [@jdx](https://github.com/jdx) in [#602](#602) - prefix star count with ★ glyph and populate it on deploy by [@jdx](https://github.com/jdx) in [#606](#606) - integrate Commander.js, oclif and yargs by [@gaojunran](https://github.com/gaojunran) in [#616](#616) - integrate Typer and Click by [@gaojunran](https://github.com/gaojunran) in [#619](#619) ### 🔍 Other Changes - **(docs)** remove shrill.en.dev analytics script by [@jdx](https://github.com/jdx) in [#614](#614) - **(release)** append en.dev sponsor blurb to release notes by [@jdx](https://github.com/jdx) in [#598](#598) - switch analytics from gtm to plausible by [@jdx](https://github.com/jdx) in [#609](#609) - pin taiki-e/install-action to commit SHA by [@jdx](https://github.com/jdx) in [#610](#610) - rename CLAUDE.md to AGENTS.md and symlink by [@jdx](https://github.com/jdx) in [#618](#618) ### 📦️ Dependency Updates - bump communique to 1.1.2 by [@jdx](https://github.com/jdx) in [#605](#605) - lock file maintenance by [@renovate[bot]](https://github.com/renovate[bot]) in [#607](#607) - update autofix-ci/action action to v1.3.4 by [@renovate[bot]](https://github.com/renovate[bot]) in [#611](#611) - update apple-actions/import-codesign-certs action to v7 by [@renovate[bot]](https://github.com/renovate[bot]) in [#612](#612) - update taiki-e/install-action digest to fc9eae0 by [@renovate[bot]](https://github.com/renovate[bot]) in [#613](#613) --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
|
Thanks!! |

Summary
Adds
usage g completion-init <shell>(bash/zsh/fish) — a one-time init script users source from their shell rc to enable<Tab>completion for any command on\$PATHwhose first line is ausageshebang. No per-scriptusage g completion bash <bin> -f <script>generation required.Closes the docs gap reported in #617 where users expected shebang scripts on $PATH to gain completion automatically.
Mechanism per shell
complete -Ddefault handler. On<Tab>, resolves the candidate command, peeks line 1 for#!*usage*, and dispatches tousage complete-word. Chains to_completion_loaderfor non-usage commands so bash-completion's dynamic loader still works.compdef -default-fallback. Same shebang detection. Falls back to_filesfor non-usage commands.-default-equivalent, so the init scans\$PATHonce at shell startup and registerscomplete -c <name>per usage shebang script. One-time cost proportional to\$PATHsize.Tests
Three integration tests in
cli/tests/shell_completions_integration.rsdrive each shell against a staged usage shebang script and assert on the resulting completion candidates (positional, flag, partial flag).The existing "skip if shell missing" pattern was bumped:
skip_if_shell_missing()now panics underCI=1to prevent silent false-positives if a shell is missing in CI.Test plan
cargo test --all --all-featurespassescargo clippy --all --all-features -- -D warningscleanmise run cigreenCI=1 cargo test -p usage-cli --test shell_completions_integration— all 9 passexamples/example.shasexon PATH, source init in each shell, verify<Tab>producesval-1 val-2 val-3and flag completionNote
Medium Risk
Adds new shell init scripts that install default completion handlers (bash
complete -D, zshcompdef -default-) and a fish$PATHscan, which could interfere with users’ existing completion setups or impact shell startup performance. CI changes also alter workflow behavior by requiring additional packages and making missing shells in CI a hard failure.Overview
Adds a new
usage generate completion-init(aliasci) subcommand that outputs a one-time init script forbash/zsh/fish, enabling tab-completion for any executable on$PATHwhose first line is ausageshebang by dispatching tousage complete-word.Implements shell-specific init generators in
lib/src/complete/(including bash default-handler chaining and fish startup$PATHscanning), wires them into the CLI, and expands integration tests to covercompletion-initbehavior plus stricter “skip” logic (panic when shells are missing underCI).Updates generated docs/manpage/Fig spec/reference JSON and adjusts GitHub Actions workflows to install
zsh,fish, and ensurepwshis available so the new integration tests run reliably in CI.Reviewed by Cursor Bugbot for commit 55c1d36. Bugbot is set up for automated code reviews on this repo. Configure here.