添加新的 zshell 命令行自定义 git 补全
我通过 Homebrew 安装了 git。我通过安装的脚本获得命令行补全,
/usr/local/etc/bash_completion.d/
但是我希望我的自定义 git-* 脚本也能完成。
我如何将其添加到现有的 git 补全中?
I installed git via Homebrew. I get command line completions via the script installed in
/usr/local/etc/bash_completion.d/
However I want my custom git-* scripts to be completed too.
How would I tack this on to existing git completions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我给你举几个例子。
如果您有一个像这样的 pull 别名:
那么您可以定义别名以使用与 git-push 相同的补全功能。
这是一项比较困难的任务。为 zsh 编写完成脚本并不简单,您可以看一下 在这个项目中寻求一些指导。例如,查看完成脚本 for git-wtf
如果您有要在日志中搜索的脚本喜欢this:
您想要使用 git-log 的补全,并进行一些小修改:您想要首先完成搜索字符串,然后使用 git-log 的常用选项>。然后你可以使用这个:
编辑:此外,要实际使用新定义的完成文件,你必须将存储它们的目录添加到
fpath
I'll give you a couple of examples.
If you have an alias for pull like this one:
then you can define the alias to use the same completion as
git-push
by doing.This is a tougher one. Writing completion scripts for zsh is not trivial, you can take a look at the ones in this project for some guidance. For example, take a look at the completion script for git-wtf
If you have a script to search in the log like this:
You want to use the copmletion of
git-log
, with a small modification: You want to complete first for a search string and then use the usual options forgit-log
. Then you can use this:EDIT: Also, to actually use your newly defined completion files, you have to add the directory where they are stored to the
fpath