Zsh tab completion for capistrano


#1

I got tired of typing out things like “cap production
restart_mongrel_cluster” (and can never remember whether it’s
restart_mongrel_cluster or mongrel_cluster_restart"), so I hacked
together a capistrano tab-completion script. Thought others might be
interested, so here it is :

######################

To use, save as .cap_completion.zsh in your home dir, and add

“source .cap_completion.zsh” to your .zshrc file

99% of this is ripped straight from

http://weblog.rubyonrails.com/2006/3/9/fast-rake-task-completion-for-zsh

Any broken stuff is probably mine.

_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 show_tasks -q | cut -d " " -f 1 | sed -e ‘/^ *$/D’ -e ‘1,2D’

.cap_tasks
fi
compadd cat .cap_tasks
fi
}

compdef _cap cap
######################

Would love to see any improvements - my script-fu is weak.

Jon