Browse code

Merge pull request #850 from johnantoni/pow-fix

take in chris sexton's changes to the pow plugin

Robby Russell authored on 26/01/2012 at 02:15:16
Showing 1 changed files
... ...
@@ -1,10 +1,66 @@
1
-# Thanks to Christopher Sexton
2
-# https://gist.github.com/965032
3
-function kapow {
4
-	touch ~/.pow/$1/tmp/restart.txt
5
-	if [ $? -eq 0 ]; then
6
-		echo "$fg[yellow]Pow restarting $1...$reset_color"
7
-	fi
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)//"`
8 36
 }
9 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
+}
10 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/*"