]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/pow/pow.plugin.zsh
0b8ccd15b64e6ea6b2a86bdea233acf7153449ec
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / pow / pow.plugin.zsh
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
22 rack_root(){
23   setopt chaselinks
24   local orgdir="$PWD"
25   local basedir="$PWD"
26
27   while [[ $basedir != '/' ]]; do
28     test -e "$basedir/config.ru" && break
29     builtin cd ".." 2>/dev/null
30     basedir="$PWD"
31   done
32
33   builtin cd "$orgdir" 2>/dev/null
34   [[ ${basedir} == "/" ]] && return 1
35   echo $basedir
36 }
37
38 rack_root_detect(){
39   basedir=$(rack_root)
40   echo `basename $basedir | sed -E "s/.(com|net|org)//"`
41 }
42
43 kapow(){
44   local vhost=$1
45   [ ! -n "$vhost" ] && vhost=$(rack_root_detect)
46   if [ ! -h ~/.pow/$vhost ]
47   then
48     echo "pow: This domain isn’t set up yet. Symlink your application to ${vhost} first."
49     return 1
50   fi
51
52   [ ! -d ~/.pow/${vhost}/tmp ] && mkdir -p ~/.pow/$vhost/tmp
53   touch ~/.pow/$vhost/tmp/restart.txt;
54   [ $? -eq 0 ] &&  echo "pow: restarting $vhost.dev"
55 }
56 compctl -W ~/.pow -/ kapow
57
58 powit(){
59   local basedir="$PWD"
60   local vhost=$1
61   [ ! -n "$vhost" ] && vhost=$(rack_root_detect)
62   if [ ! -h ~/.pow/$vhost ]
63   then
64     echo "pow: Symlinking your app with pow. ${vhost}"
65     [ ! -d ~/.pow/${vhost} ] && ln -s "$basedir" ~/.pow/$vhost
66     return 1
67   fi
68 }
69
70 powed(){
71   local basedir="$(rack_root)"
72   find ~/.pow/ -type l -lname "*$basedir*" -exec basename {}'.dev' \;
73 }
74
75 # Restart pow process
76 # taken from https://www.matthewratzloff.com
77 repow(){
78   lsof | grep 20560 | awk '{print $2}' | xargs kill -9
79   launchctl unload ~/Library/LaunchAgents/cx.pow.powd.plist
80   launchctl load ~/Library/LaunchAgents/cx.pow.powd.plist
81   echo "restarted pow"
82 }
83
84 # View the standard out (puts) from any pow app
85 alias kaput="tail -f ~/Library/Logs/Pow/apps/*"