我试图为一些自定义的ant参数添加自动完成。然而,它似乎是覆盖现有的哦,我的zsh蚂蚁插件自动完成,我想保持。有没有一种简单的方式,既可以让我的zsh插件和我的自定义蚂蚁自动完成和谐生活?
以下是~/.oh-my-zsh/plugins/ant/ant.plugin.zsh现有的插件
_ant_does_target_list_need_generating () {
[ ! -f .ant_targets ] && return 0;
[ build.xml -nt .ant_targets ] && return 0;
return 1;
}
_ant () {
if [ -f build.xml ]; then
if _ant_does_target_list_need_generating; then
ant -p | awk -F " " 'NR > 5 { print lastTarget }{lastTarget = $1}' > .ant_targets
fi
compadd -- `cat .ant_targets`
fi
}
compdef _ant ant我的汽车在~/my_completions/_ant完成了
#compdef ant
_arguments '-Dprop=-[properties file]:filename:->files' '-Dsrc=-[build directory]:directory:_files -/'
case "$state" in
files)
local -a property_files
property_files=( *.properties )
_multi_parts / property_files
;;
esac这是我的$fpath,我的完成路径在列表的前面,我猜这就是为什么我的脚本优先。
/Users/myusername/my_completions /Users/myusername/.oh-my-zsh/plugins/git /Users/myusername/.oh-my-zsh/functions /Users/myusername/.oh-my-zsh/completions /usr/local/share/zsh/site-functions /usr/share/zsh/site-functions /usr/share/zsh/5.0.8/functions发布于 2019-02-17 01:33:20
我认为最好的方法是扩展完成功能。下面是如何做到这一点:https://unix.stackexchange.com/a/450133
首先,您需要找到现有函数的名称,为此,可以将_complete_help绑定到CTRL(或任何其他快捷方式),然后键入命令并查找完成函数。下面是一个为git运行它的示例:
% bindkey '^h' _complete_help
% git [press ctrl-h]
tags in context :completion::complete:git::
argument-1 options (_arguments _git)
tags in context :completion::complete:git:argument-1:
aliases main-porcelain-commands user-commands third-party-commands ancillary-manipulator-commands ancillary-interrogator-commands interaction-commands plumbing-manipulator-commands plumbing-interrogator-commands plumbing-sync-commands plumbing-sync-helper-commands plumbing-internal-helper-commands (_git_commands _git)在这种情况下,完成函数是_git。接下来,您可以在.zshrc中像这样重新定义它:
# Call the function to make sure that it is loaded.
_git 2>/dev/null
# Save the original function.
functions[_git-orig]=$functions[_git]
# Redefine your completion function referencing the original.
_git() {
_git-orig "$@"
...
}您不需要再次调用compdef,因为它已经绑定到该函数,并且您只是更改了函数定义。
https://unix.stackexchange.com/questions/477142
复制相似问题