Skip to content

feat: add shell completion - #171

Merged
yoannfleurydev merged 1 commit into
mainfrom
yoannfleurydev/autocomplete-on-tab
Oct 21, 2026
Merged

yoannfleurydev merged 1 commit into
mainfrom
yoannfleurydev/autocomplete-on-tab

Conversation

@yoannfleurydev

Copy link
Copy Markdown
Owner

Closes #28

Summary

Dynamic shell completion with clap_complete's CompleteEnv (COMPLETE=<shell> gitweb) for bash, zsh, fish, elvish and PowerShell. Besides the options, it suggests values read from the current repository:

 main
+  CompleteEnv::with_factory(Opt::command).complete()   # answers COMPLETE=<shell>, then exits
   Opt::parse()
   run(opt)

 Opt
-  --branch
+  --branch  -> git::get_branches   # local + remote-tracking (prefix stripped), deduped, sorted, no HEAD
-  --tag
+  --tag     -> git::get_tags
-  --remote
+  --remote  -> git::get_remotes

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 | source loaded, in this repo:

    $ complete -C "gitweb -b "
    ci/improve-actions
    dependabot/cargo/thiserror-2.0.21     # remote-only, origin/ stripped
    feat/update-dependencies
    main                                  # local + origin/main merged, origin/HEAD dropped
    yoannfleurydev/autocomplete-on-tab
    $ complete -C "gitweb -t v0.3"
    v0.3.0 … v0.3.5
    $ complete -C "gitweb -r "
    origin
    $ cd /tmp; complete -C "gitweb -b "
    (nothing)
    

    I also drove the zsh and bash protocols directly and got the same candidates.

  • New tests: git::tests builds a throwaway repo (local branch, remote-tracking branches, origin/HEAD, tags, two remotes) and checks the three helpers. options::tests runs Opt::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 COMPLETE variable name, which Homebrew's shell_parameter_format: :clap expects.

Blast Radius: small

  • CompleteEnv only takes over when COMPLETE is set to a known shell name. Otherwise gitweb runs as before.
  • clap_complete is pinned to =4.6.11 because dynamic completion is behind the unstable-dynamic feature and cargo install gitweb ignores Cargo.lock. Dependabot bumps will need a manual look.
  • clap now requires 4.6 (needed by clap_complete). The lockfile was already on 4.6.7.

Follow-up after release: update the homebrew-gitweb formula to use generate_completions_from_executable(bin/"gitweb", shell_parameter_format: :clap).

🤖 Generated with Claude Code

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>
@yoannfleurydev
yoannfleurydev merged commit 9ccf683 into main Oct 21, 2026
2 checks passed
@yoannfleurydev
yoannfleurydev deleted the yoannfleurydev/autocomplete-on-tab branch October 21, 2026 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Autocomplete on tab

1 participant