假设您有自己的git子命令(git将运行程序git-foo
当您运行"git foo"时,您希望"git f"完成该子项
命令名称.您可以将该子命令告知完成
通过用户命令样式:
Say you got your own git sub-commands (git will run a program `git-foo'
when you run "git foo") and you want "git f" to complete that sub
commands name for you. You can make that sub-command known to the completion
via the user-command style:
% zstyle ':completion:*:*:git:*' user-commands foo:'description for foo'
`user-commands'是一种列表样式,因此您可以在其中添加任意数量的程序.
:description部分是可选的,因此您可以从中添加所有git- *程序
您的$ path像这样:
`user-commands' is a list style, so you can add any number of programs there.
The :description part is optional, so you could add all git-* programs from
your $path like this:
% zstyle ':completion:*:*:git:*' user-commands ${${(M)${(k)commands}:#git-*}/git-/}
也就是说,添加就足够了
That is, it suffices to add
zstyle ':completion:*:*:git:*' user-commands new-branch:'custom new branch function'
到您的zshrc
.
如果您也想处理自定义命令的参数,那么使用自定义compdef文件是更好的解决方案.上面引用的文件还包含一些详细信息:只需创建定义git-<yourcommand>
函数的标准定义文件,默认的gitcomplete就会在需要时自动使用它.
If you would like to handle parameters to your custom command as well, then it is a better solution to use a custom compdef file. The file referenced above has some details on that as well: Just create a standard definition file defining a git-<yourcommand>
function, the default git completion will use it automatically when needed.
这篇关于如何添加自定义git命令到zsh完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!