在bash别名Git自动完成? [英] Git autocomplete in bash aliases?

查看:85
本文介绍了在bash别名Git自动完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 go 作为 git checkout branchname 的简单bash别名。我错过的是自动完成功能,它可以与完整的 git checkout branchna ... 命令一起使用,但不在别名中。

I'm using go as a simple bash alias for git checkout branchname. The thing that I miss is the autocomplete feature that works with the full git checkout branchna... command, but not in the alias.

是否有办法指示Bash为另一个命令继承自动完成驱动程序?

Is there a way to instruct Bash to "inherit" the autocomplete "driver" for another command?

推荐答案

如果您可以找到原始命令使用的完成功能,您可以使用完成-F 将其分配给别名。

If you can find out the completion function used by the original command, you can assign it to the alias using complete -F.

例如,在我的Ubuntu机器上, git checkout 使用的完成函数是 _git_checkout (找到在 /etc/bash_complete.d/git )。

For example, on my ubuntu box, the completion function used by git checkout is _git_checkout (found in /etc/bash_complete.d/git).

在运行完成-F 之前:

[me@home]$ git checkout <TAB><TAB>
HEAD            master          origin/HEAD     origin/master

[me@home]$ alias go="git checkout"

[me@home]$$ go <TAB><TAB>
.git/                precommit_config.py  README.md            SvnSentinel/         
.gitignore           precommit.py         startcommit.py       tests/ 

后:

After:

[me@home]$$ complete -F _git_checkout go

[me@home]$$ go <TAB><TAB>
HEAD            master          origin/HEAD     origin/master 

这篇关于在bash别名Git自动完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆