Reputation: 4972
I installed git via Homebrew. I get command line completions via the script installed in
/usr/local/etc/bash_completion.d/
However I want my custom git-* scripts to be completed too.
How would I tack this on to existing git completions?
Upvotes: 4
Views: 635
Reputation: 47279
I'll give you a couple of examples.
If you have an alias for pull like this one:
alias gp='git push'
then you can define the alias to use the same completion as git-push
by doing.
compdef _git gp=git-push
This is a tougher one. Writing completion scripts for zsh is not trivial, you can take a look at the ones in this project for some guidance. For example, take a look at the completion script for git-wtf
If you have a script to search in the log like this:
query="$1"
shift
git log -S"$query" "$@"
You want to use the copmletion of git-log
, with a small modification: You want to complete first for a search string and then use the usual options for git-log
. Then you can use this:
_git-search () {
if (( CURRENT == 2 )); then
_message "search string"
return
fi
CURRENT=$(( $CURRENT - 1 ))
_git-log
}
_git-search "$@"
EDIT: Also, to actually use your newly defined completion files, you have to add the directory where they are stored to the fpath
Upvotes: 3