Eri*_*tch 10 zsh git autocomplete
function g() {
# Handle arguments [...]
}
Run Code Online (Sandbox Code Playgroud)
在其中,我处理执行 Git 命令的简短参数。例如:
g ls # Executes git ls-files ...
g g # Executes git grep ...
Run Code Online (Sandbox Code Playgroud)
我需要能够将自动完成规则设置为 Git 的短参数规则,但我不确定如何执行此操作。
例如,我需要g ls <TAB>
使用制表符完成规则,git ls-files <TAB>
这些规则将为我提供以下参数git ls-files
:
$ g ls --<TAB>
--abbrev -- set minimum SHA1 display-length
--cached -- show cached files in output
--deleted -- show deleted files in output
# Etc...
Run Code Online (Sandbox Code Playgroud)
这不仅仅是设置g
为自动完成,git
因为我将自定义短命令映射到 Git 命令。
我发现/usr/share/zsh/functions/Completion/Unix/_git
其中有一些关于像这样的别名的提示,并最终为别名定义了这些函数:
_git-ls () {
# Just return the _git-ls-files autocomplete function
_git-ls-files
}
Run Code Online (Sandbox Code Playgroud)
然后,我做了一个顺子compdef g=git
。例如,自动完成系统会看到您正在运行,g ls
并使用_git-ls
自动完成功能。
感谢 user67060 引导我走向正确的方向。