是'cap`一个保留字? - zsh完成?

时间:2014-01-25 17:41:42

标签: zsh oh-my-zsh zsh-completion

我正在尝试为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一起使用。

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

两种解决方案都使用shipit代替cap

$ shipit |
production staging

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

1 个答案:

答案 0 :(得分:0)

是的,cap是ZSH内置的。引用from zsh docs

  

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

     

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