Frage

I'm trying to create a Capistrano mutilstage completion for ZSH:

$ cap |
production staging


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

Completion code:

#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

The problem:

#compdef cap doesn't work. If I type cap and [TAB] it doesn't execute the completion, but with other words (i.e. shipit) works fine.

Any ideas?

Solution:

cap is really a reserved word and it seems that we can't use it with #compdef cap.

I'm wondering how cap and capistrano completions worked before (maybe an old version of ZSH).

Both solutions use shipit instead of cap.

$ shipit |
production staging

$ shipit production |
deploy                       -- Deploy a new release
deploy:bundle                -- Bundle
...
War es hilfreich?

Lösung

Yes, cap is a ZSH builtin. Quoting from zsh docs:

The zsh/cap module is used for manipulating POSIX.1e (POSIX.6) capability sets. [...]. The builtins in this module are:

cap [ capabilities ] Change the shell’s process capability sets to the specified capabilities, otherwise display the shell’s current capabilities.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top