如何让 bash 完成以使用别名? [英] How do I get bash completion to work with aliases?
问题描述
举个例子:
我在 mac 上使用 bash v3.2.17,我正在使用通过 macports 安装的 git 和 bash_completion 变体.
I'm a on mac with bash v3.2.17, I'm using git installed via macports with the bash_completion variant.
当我输入 git checkout m
时.例如,我把它完成给master
.
When I type git checkout m<tab>
. for example, I get it completed to master
.
但是,我有 git checkout
的别名,gco
.当我输入 gco m
时,我没有自动完成分支名称.
However, I've got an alias to git checkout
, gco
. When I type gco m<tab>
, I don't get the branch name autocompleted.
理想情况下,我希望自动完成功能可以神奇地适用于我的所有别名.是否可以?否则,我想为每个别名手动自定义它.那么,我该怎么做呢?
Ideally I'd like autocompletion to just magically work for all my aliases. Is it possible? Failing that, I'd like to manually customize it for each alias. So, how do I go about either?
推荐答案
如以上评论所述,
complete -o default -o nospace -F _git_checkout gco
将不再起作用.但是,在 git-completion.bash 中有一个 __git_complete
函数,可用于为别名设置完成,如下所示:
will no longer work. However, there's a __git_complete
function in git-completion.bash which can be used to set up completion for aliases like so:
__git_complete gco _git_checkout
这篇关于如何让 bash 完成以使用别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!