https://gist.github.com/1019777/70dbb46db9bd5b346faf543a9dd4edac4782adda
| ... | ... |
@@ -4,7 +4,6 @@ |
| 4 | 4 |
# Adds a kapow command that will restart an app |
| 5 | 5 |
# |
| 6 | 6 |
# $ kapow myapp |
| 7 |
-# $ kapow # defaults to current directory |
|
| 8 | 7 |
# |
| 9 | 8 |
# Supports command completion. |
| 10 | 9 |
# |
| ... | ... |
@@ -12,14 +11,40 @@ |
| 12 | 12 |
# |
| 13 | 13 |
# autoload -U compinit compinit |
| 14 | 14 |
# |
| 15 |
-# Thanks also to Christopher Sexton |
|
| 16 |
-# https://gist.github.com/965032 |
|
| 15 |
+# Changes: |
|
| 17 | 16 |
# |
| 18 |
-function kapow {
|
|
| 19 |
- FOLDERNAME=$1 |
|
| 20 |
- if [ -z "$FOLDERNAME" ]; then; FOLDERNAME=${PWD##*/}; fi
|
|
| 21 |
- touch ~/.pow/$FOLDERNAME/tmp/restart.txt; |
|
| 22 |
- if [ $? -eq 0 ]; then; echo "pow: restarting $FOLDERNAME" ; fi |
|
| 17 |
+# Defaults to the current application, and will walk up the tree to find |
|
| 18 |
+# a config.ru file and restart the corresponding app |
|
| 19 |
+# |
|
| 20 |
+# Will Detect if a app does not exist in pow and print a (slightly) helpful |
|
| 21 |
+# error message |
|
| 22 |
+ |
|
| 23 |
+rack_root_detect(){
|
|
| 24 |
+ setopt chaselinks |
|
| 25 |
+ local orgdir=$(pwd) |
|
| 26 |
+ local basedir=$(pwd) |
|
| 27 |
+ |
|
| 28 |
+ while [[ $basedir != '/' ]]; do |
|
| 29 |
+ test -e "$basedir/config.ru" && break |
|
| 30 |
+ builtin cd ".." 2>/dev/null |
|
| 31 |
+ basedir="$(pwd)" |
|
| 32 |
+ done |
|
| 33 |
+ |
|
| 34 |
+ builtin cd $orgdir 2>/dev/null |
|
| 35 |
+ [[ ${basedir} == "/" ]] && return 1
|
|
| 36 |
+ echo `basename $basedir | sed -E "s/.(com|net|org)//"` |
|
| 23 | 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 |
|
| 24 | 46 |
|
| 25 |
-compctl -W ~/.pow -/ kapow |
|
| 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 |
|
| 26 | 52 |
\ No newline at end of file |