How to bash complete an alias as the command

1

2

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

Posted 2015-11-23T13:27:58.363

Reputation: 133

Question was closed 2015-12-04T19:02:38.367

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 – 2018-07-26T21:57:09.353

Answers

3

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

Posted 2015-11-23T13:27:58.363

Reputation: 318