我正在尝试为 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 确实是一个保留字,似乎我们不能将它与#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
...