Ken*_*ams 10 git zsh tab-completion zsh-completion git-alias
我有一个 Git 别名update,我想为其配备分支名称完成功能。别名定义如下:
[alias]
update = "!f() { git push . origin/$1:$1; }; f"
Run Code Online (Sandbox Code Playgroud)
(它使用其上游版本更新本地跟踪分支,而无需检查该分支。不过,对于特定问题并不重要。)
我希望该命令为其$1参数补全现有的分支名称。我知道我可以定义一个调用_git-update来控制完成的函数,但是我缺少一些使其工作的部分:
_git-update ()
{
***some-function-here*** "$(__git_branch_names)"
}
Run Code Online (Sandbox Code Playgroud)
我正在使用安装在 OS X 上的完成brew install zsh-completions,这是在https://github.com/zsh-users/zsh-completions设置的。
(这个问题直接类似于/sf/answers/2891556601/,但针对 Zsh 而不是 Bash。)
可能有点先发制人,但这是有效的:
# provides completion options similar to git branch/rebase/log
_complete_like_git_branch() {
__gitcomp_nl_append "FETCH_HEAD"
__gitcomp_nl_append "HEAD"
__gitcomp_nl_append "ORIG_HEAD"
__gitcomp_nl_append "$(__git_heads)"
__gitcomp_nl_append "$(__git_remote_heads)"
__gitcomp_nl_append "$(__git_tags)"
__gitcomp_nl_append "$(__git_complete_refs)"
}
_git_rebase_chain() { _complete_like_git_branch }
# my git "bang" alias of git log
_git_lgk() { _complete_like_git_branch }
Run Code Online (Sandbox Code Playgroud)
参考:contrib/completion/git-completion.bash
可能的改进:
~/.zshrc?| 归档时间: |
|
| 查看次数: |
578 次 |
| 最近记录: |