Forum: Rails deployment Zsh tab completion for capistrano

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A9e5ce6f28587baa2a566eb4f2d76c13?d=identicon&s=25 Jon (Guest)
on 2007-04-23 14:07
(Received via mailing list)
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-t...
# 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
This topic is locked and can not be replied to.