pow.plugin.zsh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Restart a rack app running under pow
  2. # http://pow.cx/
  3. #
  4. # Adds a kapow command that will restart an app
  5. #
  6. # $ kapow myapp
  7. #
  8. # Supports command completion.
  9. #
  10. # If you are not already using completion you might need to enable it with
  11. #
  12. # autoload -U compinit compinit
  13. #
  14. # Changes:
  15. #
  16. # Defaults to the current application, and will walk up the tree to find
  17. # a config.ru file and restart the corresponding app
  18. #
  19. # Will Detect if a app does not exist in pow and print a (slightly) helpful
  20. # error message
  21. rack_root_detect(){
  22. setopt chaselinks
  23. local orgdir=$(pwd)
  24. local basedir=$(pwd)
  25. while [[ $basedir != '/' ]]; do
  26. test -e "$basedir/config.ru" && break
  27. builtin cd ".." 2>/dev/null
  28. basedir="$(pwd)"
  29. done
  30. builtin cd $orgdir 2>/dev/null
  31. [[ ${basedir} == "/" ]] && return 1
  32. echo `basename $basedir | sed -E "s/.(com|net|org)//"`
  33. }
  34. kapow(){
  35. local vhost=$1
  36. [ ! -n "$vhost" ] && vhost=$(rack_root_detect)
  37. if [ ! -h ~/.pow/$vhost ]
  38. then
  39. echo "pow: This domain isn’t set up yet. Symlink your application to ${vhost} first."
  40. return 1
  41. fi
  42. [ ! -d "~/.pow/${vhost}/tmp" ] && mkdir -p "~/.pow/$vhost/tmp"
  43. touch ~/.pow/$vhost/tmp/restart.txt;
  44. [ $? -eq 0 ] && echo "pow: restarting $vhost.dev"
  45. }
  46. compctl -W ~/.pow -/ kapow