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.
It can really save you a lot of typing. If there is more than one possibility, then it will let you know that it needs more information and you can type a little bit more of the word and try again. Git auto-completion is a separate script, and it's included inside the Git source code repository on GitHub.
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.
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