Zsh Capistrano Task Completion on OS X

The Zsh task completion I found for Capistrano was a bit out of date.

The following is working for me:

_cap_does_task_list_need_generating () {
  if [ ! -f .cap_tasks ]; then 
    return 0;
  else
    accurate=$(stat -f%m .cap_tasks)
    changed=$(stat -f%m config/deploy.rb)
    return $(expr $accurate '>=' $changed)
  fi
}

_cap () {
  if [ -f config/deploy.rb ]; then
    if _cap_does_task_list_need_generating; then
      echo "\nGenerating .cap_tasks..." > /dev/stderr
      cap -vT | awk 'FB != 1 {if ($0 ~ /^$/){FB=1}else{print $2}}' > .cap_tasks
    fi
    compadd `cat .cap_tasks`
  fi
}

compdef _cap cap

Based on rake task completion.
Put it somewhere like ~/.zsh/cap_completion and add the following to ~/.zshrc or ~/.zprofile

 # enable completion if you haven't already
autoload -U compinit
compinit
 
# load capistrano completion
source ~/.zsh/cap_completion

Loading mentions Retweet
Posted 8 months ago

0 comments

Leave a comment...

 
To leave a comment on this posterous, please login by clicking one of the following.
Posterous-login     Connect     twitter