Skip to content

feat(cli): add completion subcommand for shell completion scripts - #555

Merged
altsem merged 2 commits into
altsem:masterfrom
ChrisJr404:feat/shell-completions
Aug 22, 2026
Merged

feat(cli): add completion subcommand for shell completion scripts#555
altsem merged 2 commits into
altsem:masterfrom
ChrisJr404:feat/shell-completions

Conversation

@ChrisJr404

Copy link
Copy Markdown
Contributor

Closes #544.

Adds a completion subcommand that prints a shell completion script to stdout, generated with clap_complete:

gitu completion bash > ~/.local/share/bash-completion/completions/gitu

Supported shells are bash, elvish, fish, powershell and zsh (whatever clap_complete::Shell offers). Since generating a script doesn't need a terminal or a git repository, it's handled early in main, right alongside --version, and returns before any of that setup runs.

Changes

  • src/cli.rs: new Commands::Completion { shell } variant and a small completions(shell, out) helper that writes the script to any Write (keeps the generation testable and lets main pass stdout).
  • src/main.rs: handle the subcommand before terminal/repo setup.
  • src/app.rs: the completion arm is unreachable! here since it never reaches app construction.
  • Docs: a "Shell completions" section in docs/installing.md with per-shell install paths, plus a one-line pointer from the README.

Tests

Added src/tests/completion.rs covering: the subcommand parses, an unknown shell is rejected, and every supported shell produces a non-empty script that references the binary name.

test tests::completion::completion_rejects_unknown_shell ... ok
test tests::completion::completion_subcommand_parses ... ok
test tests::completion::generates_non_empty_script_for_every_shell ... ok

cargo fmt --check and cargo clippy -- -Dwarnings are clean. (The pre-existing fetch/pull/push snapshot tests fail in my sandbox on a clean master too — they're unrelated to this change.)

Happy to adjust the subcommand name or wire the scripts into the release artifacts instead if you'd prefer that approach.

ChrisJr404 and others added 2 commits August 18, 2026 14:56
Add a `gitu completion <shell>` subcommand that prints a completion
script to stdout for bash, elvish, fish, powershell or zsh, generated
with clap_complete. It is handled before terminal setup and git repo
discovery, so it works from anywhere.

Closes altsem#544
@altsem
altsem merged commit 53edd1c into altsem:master Aug 22, 2026
3 checks passed
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.

[Feature Request] shell completion for bash, zsh, fish

2 participants