0

我正在尝试为 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.

我想知道capcapistrano完成之前是如何工作的(可能是 ZSH 的旧版本)。

两种解决方案都使用shipit而不是cap.

$ shipit |
production staging

$ shipit production |
deploy                       -- Deploy a new release
deploy:bundle                -- Bundle
...
4

1 回答 1

0

是的,cap是内置的 ZSH。引用zsh 文档

zsh/cap 模块用于操作 POSIX.1e (POSIX.6) 能力集。[...]。该模块中的内置函数是:

cap [ 能力 ]将 shell 的进程能力集更改为指定的能力,否则显示 shell 的当前能力。

于 2014-01-25T17:44:15.097 回答