pow.plugin.zsh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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
  47. powit(){
  48. local basedir=$(pwd)
  49. local vhost=$1
  50. [ ! -n "$vhost" ] && vhost=$(rack_root_detect)
  51. if [ ! -h ~/.pow/$vhost ]
  52. then
  53. echo "pow: Symlinking your app with pow. ${vhost}"
  54. [ ! -d ~/.pow/${vhost} ] && ln -s $basedir ~/.pow/$vhost
  55. return 1
  56. fi
  57. }
  58. # View the standard out (puts) from any pow app
  59. alias kaput="tail -f ~/Library/Logs/Pow/apps/*"