1

I have an alias

alias gi=git

Unlike git, gi cannot complete on subcommands, paths, branches.

How can I tell bash to "complete X as if it were Y"?

jalanb
  • 133
  • 6
  • 6
    https://superuser.com/questions/436314/how-can-i-get-bash-to-perform-tab-completion-for-my-aliases ? – JohannesM Nov 23 '15 at 13:42
  • 1
    The answer here is better than the ones at https://superuser.com/questions/436314/how-can-i-get-bash-to-perform-tab-completion-for-my-aliases . I'm going to add it there as well. – wisbucky Jul 26 '18 at 21:57

1 Answers1

4

You'll probably want to add this to your .bashrc or .bash_aliases.

# load git completions
_completion_loader git

# assign git's completion function _git to gi
complete -o bashdefault -o default -o nospace -F _git gi

Alternatively you can use the following (which is pretty much equivalent):

# load git completions
. /usr/share/bash-completion/completions/git

# assign git's completion function _git to gi
__git_complete gi _git

Note, you can skip the first line (of either of the aforementioned examples) if dynamic completions are not enabled. You should probably assume it is enabled though.

Six
  • 358
  • 1
  • 5