Repository navigation
feat: add shell completion - #171
Merged
Merged
Conversation
Complete the options on TAB for bash, zsh, fish, elvish and PowerShell with clap_complete's dynamic completion (COMPLETE=<shell> gitweb), and suggest the branches, tags and remotes of the current repository for --branch, --tag and --remote. clap_complete is pinned as the dynamic completion is behind its unstable-dynamic feature and `cargo install` ignores Cargo.lock. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #28
Summary
Dynamic shell completion with
clap_complete'sCompleteEnv(COMPLETE=<shell> gitweb) for bash, zsh, fish, elvish and PowerShell. Besides the options, it suggests values read from the current repository:Outside a repository, or on any git error, a completer returns nothing and prints nothing.
The issue suggested generating scripts in GitHub Actions. With dynamic completion, the generated script is only a stub that calls back into the binary, so the README tells users to source it at shell startup instead. The stub then stays in sync across upgrades.
Evidence
Before:
gitweb -b <TAB>offers nothing (there's no completion at all).After: fish, with
COMPLETE=fish ./target/debug/gitweb | sourceloaded, in this repo:I also drove the zsh and bash protocols directly and got the same candidates.
New tests:
git::testsbuilds a throwaway repo (local branch, remote-tracking branches,origin/HEAD, tags, two remotes) and checks the three helpers.options::testsrunsOpt::command().debug_assert().cargo test: 17 passed.cargo clippy --all-features: no new warnings.Merge Danger
Door: two-way
The only lasting commitment is the
COMPLETEvariable name, which Homebrew'sshell_parameter_format: :clapexpects.Blast Radius: small
CompleteEnvonly takes over whenCOMPLETEis set to a known shell name. Otherwisegitwebruns as before.clap_completeis pinned to=4.6.11because dynamic completion is behind theunstable-dynamicfeature andcargo install gitwebignoresCargo.lock. Dependabot bumps will need a manual look.clapnow requires 4.6 (needed byclap_complete). The lockfile was already on 4.6.7.Follow-up after release: update the
homebrew-gitwebformula to usegenerate_completions_from_executable(bin/"gitweb", shell_parameter_format: :clap).🤖 Generated with Claude Code