0

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
...
Pablo Cantero
  • 6,239
  • 4
  • 33
  • 44

1 Answers1

0

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.

Stefano Sanfilippo
  • 32,265
  • 7
  • 79
  • 80
  • Thank you. So, none of these scripts https://github.com/zsh-users/zsh-completions/blob/master/src/_cap and https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/capistrano/_capistrano work? – Pablo Cantero Jan 25 '14 at 17:47
  • No, unless you use `xcap` or the like for autocompletion. You could also try to unload the `cap` with `zmodload -u cap` (if it is a module) or recompile `zsh` without `cap` (if it was enabled at compile time). The latter is not a great idea, unless you are absolutely sure you will never need `cap`. – Stefano Sanfilippo Jan 25 '14 at 21:34
  • `zmodload: no such module cap` I think it isn't a module. :/ – Pablo Cantero Jan 25 '14 at 21:36
  • In that case, find another keyword for autocompletion. Perhaps `capi` or `xcap`… – Stefano Sanfilippo Jan 25 '14 at 22:43