禁用Zsh中的远程分支的自动完成功能? [英] Disable auto-completion of remote branches in Zsh?

查看:37
本文介绍了禁用Zsh中的远程分支的自动完成功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这与>禁用远程分支的自动完成有关在Git Bash中?.

任何人都知道如何使用zsh吗?

Anyone knows how to do the same with zsh?

推荐答案

zstyle :completion::complete:git-checkout:argument-rest:headrefs command "git for-each-ref --format='%(refname)' refs/heads 2>/dev/null"

说明:

键入git checkout <Control-x><h>会调用_complete_help,这揭示了如果在当前上下文中按TAB(而不是按<Control-x><h>),则zsh补全系统将如何工作.由此可见,zsh将调用__git_heads函数来完成git分支头的名称.如果然后键入which __git_heads,则可以看到这些分支头名称是通过以下方式获得的:

Typing git checkout <Control-x><h> invokes _complete_help which exposes the internals of how zsh's completion system would act if you pressed TAB in the current context (instead of pressing <Control-x><h>). From this it is possible to see that zsh would invoke the __git_heads function to complete names of git branch heads. If you then type which __git_heads, you can see that these branch head names are obtained via:

_call_program headrefs git for-each-ref --format='"%(refname)"' refs/heads refs/remotes 2>/dev/null

幸运的是,_call_program专为允许用户更改默认行为而设计.因此,上面的zstyle命令指示zsh使用替代的git for-each-ref ...调用而不是内置的调用,您可以看到在上面的调用中,我删除了refs/remotes参数. zstyle的第一个参数是完成上下文,这里的意思是当用户完成git checkout的参数时,当完成系统请求完成headrefs标记时,因此zstyle仅会影响git checkout,而不是其他任何git子命令.

Luckily for us, _call_program is designed specifically to allow the user to change the default behaviour. So the above zstyle command instructs zsh to use an alternative git for-each-ref ... invocation instead of the built-in one, and you can see that in the invocation above, I removed the refs/remotes parameter. The first parameter to zstyle is the completion context, and here it means "whenever the completion system is requesting completion for the headrefs tag when the user is completing an argument for git checkout. So this zstyle will only affect git checkout, and not any other git sub-commands.

这篇关于禁用Zsh中的远程分支的自动完成功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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