Reputation: 875
I have implemented a custom git command by writing a shell script located in /usr/local/bin
. It works fine, but I would like the script to autocomplete branches in the command line, just like git checkout [TAB][TAB]
. How could this be done?
EDIT:
Just adding some context: git allows you to very easily add your own commands by creating a script git-$subcommandName
. In my case here git-install
, the script facilitates checking out a branch, building, packaging, and installing the source code.
Upvotes: 9
Views: 2476
Reputation: 875
Figured it out. I needed to download git bash completion (here), create a new file in /etc/bash_completion.d
with the following contents:
source ~/.git-completion.bash
_git_install ()
{
__gitcomp_nl "$(__git_refs)"
}
and then exec bash
to reload completion scripts.
Upvotes: 12