pow.plugin.zsh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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(){
  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 $basedir
  33. }
  34. rack_root_detect(){
  35. basedir=$(rack_root)
  36. echo `basename $basedir | sed -E "s/.(com|net|org)//"`
  37. }
  38. kapow(){
  39. local vhost=$1
  40. [ ! -n "$vhost" ] && vhost=$(rack_root_detect)
  41. if [ ! -h ~/.pow/$vhost ]
  42. then
  43. echo "pow: This domain isn’t set up yet. Symlink your application to ${vhost} first."
  44. return 1
  45. fi
  46. [ ! -d ~/.pow/${vhost}/tmp ] && mkdir -p ~/.pow/$vhost/tmp
  47. touch ~/.pow/$vhost/tmp/restart.txt;
  48. [ $? -eq 0 ] && echo "pow: restarting $vhost.dev"
  49. }
  50. compctl -W ~/.pow -/ kapow
  51. powit(){
  52. local basedir="$PWD"
  53. local vhost=$1
  54. [ ! -n "$vhost" ] && vhost=$(rack_root_detect)
  55. if [ ! -h ~/.pow/$vhost ]
  56. then
  57. echo "pow: Symlinking your app with pow. ${vhost}"
  58. [ ! -d ~/.pow/${vhost} ] && ln -s "$basedir" ~/.pow/$vhost
  59. return 1
  60. fi
  61. }
  62. powed(){
  63. local basedir="$(rack_root)"
  64. find ~/.pow/ -type l -lname "*$basedir*" -exec basename {}'.dev' \;
  65. }
  66. # Restart pow process
  67. # taken from http://www.matthewratzloff.com/blog/2011/12/23/restarting-pow-when-dns-stops-responding
  68. repow(){
  69. lsof | grep 20560 | awk '{print $2}' | xargs kill -9
  70. launchctl unload ~/Library/LaunchAgents/cx.pow.powd.plist
  71. launchctl load ~/Library/LaunchAgents/cx.pow.powd.plist
  72. echo "restarted pow"
  73. }
  74. # View the standard out (puts) from any pow app
  75. alias kaput="tail -f ~/Library/Logs/Pow/apps/*"