I have a Git alias update
that I would like to outfit with branch-name completion. The alias is defined like so:
[alias]
update = "!f() { git push . origin/$1:$1; }; f"
(It updates a local tracking branch with its upstream version, without having to check out the branch. Not really important to the specific question, though.)
I would like the command to tab-complete existing branch names for its $1
argument. I know I can define a function called _git-update
to control completion, but I'm missing some pieces to get it to work:
_git-update ()
{
***some-function-here*** "$(__git_branch_names)"
}
I am using the completions installed on OS X by brew install zsh-completions
, which is the set at https://github.com/zsh-users/zsh-completions .
(This question is directly analogous to https://stackoverflow.com/a/41307951/169947, but for Zsh instead of Bash.)
May be a bit preemptive, but this is working:
# provides completion options similar to git branch/rebase/log
_complete_like_git_branch() {
__gitcomp_nl_append "FETCH_HEAD"
__gitcomp_nl_append "HEAD"
__gitcomp_nl_append "ORIG_HEAD"
__gitcomp_nl_append "$(__git_heads)"
__gitcomp_nl_append "$(__git_remote_heads)"
__gitcomp_nl_append "$(__git_tags)"
__gitcomp_nl_append "$(__git_complete_refs)"
}
_git_rebase_chain() { _complete_like_git_branch }
# my git "bang" alias of git log
_git_lgk() { _complete_like_git_branch }
reference: contrib/completion/git-completion.bash
Possible improvements:
~/.zshrc
?If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With