Tuesday 9 January 2018

How to bash complete an alias as the command



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"?



Answer



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.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...