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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.