【发布时间】:2014-01-25 17:41:41
【问题描述】:
我正在尝试为 ZSH 创建 Capistrano mutilstage 补全:
$ cap |
production staging
$ cap production |
deploy -- Deploy a new release
deploy:bundle -- Bundle
...
完成代码:
#compdef cap
#autoload
# /Users/pablo/.oh-my-zsh/custom/plugins/capistrano_custom/_capistrano_custom
local curcontext="$curcontext" state line ret=1
local -a _configs
_arguments -C \
'1: :->cmds' \
'2:: :->args' && ret=0
_cap_tasks() {
if [[ ! -f .cap_tasks~ ]]; then
echo "\nGenerating .cap_tasks~..." > /dev/stderr
cap -v --tasks | grep '#' | cut -d " " -f 2 > .cap_tasks~
fi
cat .cap_tasks~
}
_cap_stages() {
find config/deploy -name \*.rb | cut -d/ -f3 | sed s:.rb::g
}
case $state in
cmds)
if [[ -d config/deploy ]]; then
compadd `_cap_stages`
else
compadd `_cap_tasks`
fi
ret=0
;;
args)
compadd `_cap_tasks`
ret=0
;;
esac
return ret
问题:
#compdef cap 不起作用。如果我输入 cap 和 [TAB] 它不会执行完成,但换句话说(即shipit)可以正常工作。
有什么想法吗?
解决方案:
cap is really a reserved word 似乎我们不能将它与#compdef cap 一起使用。
我想知道 cap 和 capistrano 之前的补全是如何工作的(可能是 ZSH 的旧版本)。
- 解决点文件代码:capistrano_custom
- 解决方案 oh-my-zsh/PR:#2471
两种解决方案都使用shipit 而不是cap。
$ shipit |
production staging
$ shipit production |
deploy -- Deploy a new release
deploy:bundle -- Bundle
...
【问题讨论】:
-
“有什么想法吗?” -- 使用
xcap,或其他合适的名称。 -
alias xcap="cap"我试过了,但还是不行。 ZSH 不喜欢用cap完成。 -
别名不起作用;原始名称也不得保留。
-
我在问题中添加了一个“解决方案”。谢谢!
-
嗨,Pablo,我如何使用你的自定义插件?
标签: zsh oh-my-zsh zsh-completion