How do I get bash completion to work with aliases?

后端 未结 12 1072
温柔的废话
温柔的废话 2020-11-28 00:35

Case in point:

I\'m a on mac with bash v3.2.17, I\'m using git installed via macports with the bash_completion variant.

When I type git checkout m<

12条回答
  •  感动是毒
    2020-11-28 01:16

    One more option is to use ~/.bash_completion file. To create the gco alias for git checkout just put this in there:

    _xfunc git __git_complete gco _git_checkout
    

    Then in ~/.bashrc you have to put just the alias itself:

    alias gco='git checkout'
    

    Two lines. That's it.

    Explanation:

    The ~/bash_completion gets sourced at the end of the main bash_completion script. In gentoo I found the main script in /usr/share/bash-completion/bash_completion.

    The _xfunc git bit takes care of sourcing the git-completion file for you so you don't need to put anything else in ~/.bashrc.

    The accepted answer require you to copy .git-completion.sh and source it from your ~/.bashrc file which I find lame.


    PS: I'm still trying to figure out how not to source the whole git-completion script into my bash environment. Please comment or edit if you find a way.

提交回复
热议问题