Add bash and zsh completions - #60
Open
leogdion wants to merge 1 commit into
Open
Conversation
Adds completions/git-trees.bash and completions/_git-trees covering every subcommand and its own flags, with branch and worktree names derived from git for `rm`. The filenames and function names are load-bearing. bash-completion's git driver dispatches `git <cmd>` to `_git_<cmd>` with dashes turned into underscores, so `git trees` requires a function named `_git_trees`. zsh's `_git` dispatches via `_call_function ret _git-$words[1]`, so it requires a file named `_git-trees` on fpath. Both files also wire up the standalone `git-trees` binary. install.sh copies both files to ~/.config/git-trees/completions/ using the same no-overwrite guard already used for AGENTS.md.template, and prints the activation line for each shell. CI gains completions/git-trees.bash in both the `bash -n` and `shellcheck` steps. completions/_git-trees is deliberately excluded from both: `#compdef` and `_arguments` are zsh syntax and are not valid bash. Closes #51 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
This was referenced Aug 21, 2026
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.
Adds bash and zsh completions for
git trees.The dispatch naming (most likely thing to review wrong)
The tool installs on
PATHasgit-treesand is invoked asgit trees. Twodifferent shells resolve that subcommand two different ways, and both names are
load-bearing:
local completion_func="_git_${command//-/_}", sogit treesdispatches to afunction named
_git_trees(underscores, not dashes). Verified against/Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash:3830._gitdoes_call_function ret _git-$words[1], sogit treesdispatches to a file named
_git-trees(dashes) found onfpath.Renaming either one silently disables completion with no error, so both files
carry a comment explaining why the name cannot change, and the README says so
too.
Each file also wires up direct invocation of the standalone
git-treesbinary(
complete -Fin bash, the#compdef git-treestag in zsh), so completionworks whether the user types
git treesorgit-trees.What is completed
Subcommands at position 1 (
init root add track list ls rm clean sync prune help), then each subcommand's own flags:init--host --dirroot--agentsadd--print-path --no-pushtrack--no-pushlist/ls--jsonrm--applyclean--merged --gone --applysync--pull --ff-only --rebaseprune--dry-runrmcompletes branch and worktree names derived from git itself(
git for-each-ref refs/headsplusgit worktree list --porcelain), never ahardcoded list. Worktree directory names are branch names slugged
/→-, sothe two sets overlap heavily and both files dedupe. The bare container root
(
trees-bare.git) is filtered out — git lists it as a worktree but it is not aremovable target.
Every git call is silenced and short-circuited: completing outside a repository
returns an empty list rather than erroring or hanging in the user's prompt.
There is a smoke assertion for exactly that.
sync / prune anticipate sibling PRs
sync [worktree] [--pull] [--ff-only|--rebase]andprune [--dry-run]arebeing added concurrently in #50 and #55. They are included here so the
completions are correct for the release as a whole. This PR merges after those
two, so it may need a rebase on
release-1.0.3first — the completionsthemselves need no change either way, since they do not read anything out of
git-treesat runtime.Verified
bash -non all four bash files,shellcheck -s bashon all four,zsh -n completions/_git-trees, andtests/smoke.sh ./git-treesall passclean.
Beyond the linters, the bash completion was exercised for real: sourcing
bash-completion's git script plus this file into a non-interactive bash,
confirming
_git_treesis defined, and drivingCOMP_WORDS/COMP_CWORDthrough it. Every row of the table above was checked, plus the empty-and-quiet
behavior outside a repo. Those probes are now part of
tests/smoke.shso theyrun in CI on both runners.
For zsh,
zsh -npasses and acompinitload test confirms the dispatch wiringresolves: with
completions/onfpath,_comps[git-trees]resolves to_git-treesand the function autoloads, defining its helpers and running its_argumentsspecs. Full interactive match capture was not possible in thisenvironment —
zsh/zptyhere does not deliver keystrokes to ZLE (a trivialcontrol-key-bound widget never fires), and
_argumentsrefuses to run outside areal completion context. That limitation is the sandbox's, not the file's, and
is called out rather than glossed over.
Why the zsh file is excluded from CI linting
completions/git-trees.bashis added to both thebash -nandshellchecksteps.
completions/_git-treesis added to neither, deliberately:#compdef,_arguments,${(f)...}and friends are zsh syntax that is not valid bash, andincluding it would fail both steps. It is covered by
zsh -nlocally and by thesmoke test asserting install.sh places it byte-identical to the source.
Install and docs
install.shcopies both files to~/.config/git-trees/completions/followingthe existing
AGENTS.md.templateshape — a secondary artifact with ano-overwrite guard — then prints where each landed and the one line needed to
activate it. A user who edits an installed copy keeps it across reinstalls;
there are smoke assertions for both the install and the guard. Every existing
install.sh behavior is preserved, and the edit is additive and tightly scoped so
it should merge cleanly with the
curl | bashbootstrap work in #54.README.mdgains a### Shell completionssubsection under## Installcovering both shells, including what to do manually if you installed via the
curl path rather than
install.sh.Closes #51
🤖 Generated with Claude Code
Release coordination (v1.0.3)
One of five PRs into
release-1.0.3(#56 prune, #58 sync, #60 completions, #59 curl install, #57 Homebrew). All five are green on CI (smoke on Linux + macOS).Suggested merge order: #56 → #58 → #60 → #59 → #57. This PR merges cleanly against every other branch.
The bash completion is fully exercised — sourced against the system
git-completion.bash, with realCOMPREPLYoutput confirmed for every subcommand and flag set. The zsh side is not.zsh -npasses andcompinitresolves the dispatch (_comps[git-trees]→_git-trees), but no actual tab-completion was ever driven through it: that needs real ZLE, andzsh/zptyin the sandbox would not deliver keystrokes to it. Please tab-testgit trees <TAB>in a real zsh before merging.Also note this PR anticipates #58 and #56:
syncandpruneare already in both completion files with their flags. If either of those PRs changes a flag name before merging, these lists need to follow.Note: CodeRabbit skipped all five — "reviews are disabled for this base branch." These have not had automated review; that would come when
release-1.0.3merges tomain.The CHANGELOG is deliberately excluded from every PR — it needs the merged PR URLs, so it lands as one commit on
release-1.0.3before taggingv1.0.3.