]> git.rmz.io Git - dotfiles.git/blob - zsh/plugins/pow/pow.plugin.zsh
399a54cb02aae802afb95f72a343b35b1412f779
[dotfiles.git] / 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_detect(){
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 `basename $basedir | sed -E "s/.(com|net|org)//"`
36 }
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
47 [ ! -d ~/.pow/${vhost}/tmp ] && mkdir -p ~/.pow/$vhost/tmp
48 touch ~/.pow/$vhost/tmp/restart.txt;
49 [ $? -eq 0 ] && echo "pow: restarting $vhost.dev"
50 }
51 compctl -W ~/.pow -/ kapow
52
53 powit(){
54 local basedir=$(pwd)
55 local vhost=$1
56 [ ! -n "$vhost" ] && vhost=$(rack_root_detect)
57 if [ ! -h ~/.pow/$vhost ]
58 then
59 echo "pow: Symlinking your app with pow. ${vhost}"
60 [ ! -d ~/.pow/${vhost} ] && ln -s $basedir ~/.pow/$vhost
61 return 1
62 fi
63 }
64
65 # View the standard out (puts) from any pow app
66 alias kaput="tail -f ~/Library/Logs/Pow/apps/*"