Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git autocomplete in bash aliases?

Tags:

git

bash

I'm using go as a simple bash alias for git checkout branchname. The thing that I miss is the autocomplete feature that works with the full git checkout branchna... command, but not in the alias.

Is there a way to instruct Bash to "inherit" the autocomplete "driver" for another command?

like image 594
Claudio Avatar asked Mar 26 '12 08:03

Claudio


People also ask

What are aliases in git?

Git aliases are a powerful workflow tool that create shortcuts to frequently used Git commands. Using Git aliases will make you a faster and more efficient developer. Aliases can be used to wrap a sequence of Git commands into new faux Git command.


1 Answers

After using complete -F:

complete -F _git_checkout go 

Tabbing after go may result in:

bash: [: 1: unary operator expected 

Instead of complete, use __git_complete

This is git bash completion's built-in function for this purpose.

After declaring your alias, bind the correct auto-complete function to it:

# Main git completions (prior to git 2.30, you an use _git instead of __git_main) alias g="git" __git_complete g __git_main  alias go="git checkout" __git_complete go _git_checkout  alias gp="git push" __git_complete gp _git_push 
like image 142
theprogrammerin Avatar answered Sep 29 '22 07:09

theprogrammerin