From 741f6747e418229deec62ae2d19c776f6494e219 Mon Sep 17 00:00:00 2001 From: John Antoni Griffiths Date: Wed, 18 Jan 2012 12:52:27 -0500 Subject: [PATCH 1/5] fix for pow plugin to default to current dir --- plugins/pow/pow.plugin.zsh | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/plugins/pow/pow.plugin.zsh b/plugins/pow/pow.plugin.zsh index 6b2a6f2be..da94b657b 100644 --- a/plugins/pow/pow.plugin.zsh +++ b/plugins/pow/pow.plugin.zsh @@ -1,10 +1,25 @@ -# Thanks to Christopher Sexton +# Restart a rack app running under pow +# http://pow.cx/ +# +# Adds a kapow command that will restart an app +# +# $ kapow myapp +# $ kapow # defaults to current directory +# +# Supports command completion. +# +# If you are not already using completion you might need to enable it with +# +# autoload -U compinit compinit +# +# Thanks also to Christopher Sexton # https://gist.github.com/965032 +# function kapow { - touch ~/.pow/$1/tmp/restart.txt - if [ $? -eq 0 ]; then - echo "$fg[yellow]Pow restarting $1...$reset_color" - fi + FOLDERNAME=$1 + if [ -z "$FOLDERNAME" ]; then; FOLDERNAME=${PWD##*/}; fi + touch ~/.pow/$FOLDERNAME/tmp/restart.txt; + if [ $? -eq 0 ]; then; echo "pow: restarting $FOLDERNAME" ; fi } compctl -W ~/.pow -/ kapow From c1a04eb61fcdd740bef52cd9da75fd72aeac3cf4 Mon Sep 17 00:00:00 2001 From: John Antoni Griffiths Date: Wed, 18 Jan 2012 12:58:13 -0500 Subject: [PATCH 2/5] take in csexton's changes https://gist.github.com/1019777/70dbb46db9bd5b346faf543a9dd4edac4782adda --- plugins/pow/pow.plugin.zsh | 45 +++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/plugins/pow/pow.plugin.zsh b/plugins/pow/pow.plugin.zsh index da94b657b..08e5cf62f 100644 --- a/plugins/pow/pow.plugin.zsh +++ b/plugins/pow/pow.plugin.zsh @@ -4,7 +4,6 @@ # Adds a kapow command that will restart an app # # $ kapow myapp -# $ kapow # defaults to current directory # # Supports command completion. # @@ -12,14 +11,40 @@ # # autoload -U compinit compinit # -# Thanks also to Christopher Sexton -# https://gist.github.com/965032 +# Changes: # -function kapow { - FOLDERNAME=$1 - if [ -z "$FOLDERNAME" ]; then; FOLDERNAME=${PWD##*/}; fi - touch ~/.pow/$FOLDERNAME/tmp/restart.txt; - if [ $? -eq 0 ]; then; echo "pow: restarting $FOLDERNAME" ; fi -} +# Defaults to the current application, and will walk up the tree to find +# a config.ru file and restart the corresponding app +# +# Will Detect if a app does not exist in pow and print a (slightly) helpful +# error message -compctl -W ~/.pow -/ kapow +rack_root_detect(){ + setopt chaselinks + local orgdir=$(pwd) + local basedir=$(pwd) + + while [[ $basedir != '/' ]]; do + test -e "$basedir/config.ru" && break + builtin cd ".." 2>/dev/null + basedir="$(pwd)" + done + + builtin cd $orgdir 2>/dev/null + [[ ${basedir} == "/" ]] && return 1 + echo `basename $basedir | sed -E "s/.(com|net|org)//"` +} +kapow(){ + local vhost=$1 + [ ! -n "$vhost" ] && vhost=$(rack_root_detect) + if [ ! -h ~/.pow/$vhost ] + then + echo "pow: This domain isn’t set up yet. Symlink your application to ${vhost} first." + return 1 + fi + + [ ! -d "~/.pow/${vhost}/tmp" ] && mkdir -p "~/.pow/$vhost/tmp" + touch ~/.pow/$vhost/tmp/restart.txt; + [ $? -eq 0 ] && echo "pow: restarting $vhost.dev" +} +compctl -W ~/.pow -/ kapow \ No newline at end of file From 36cd5ed1a59394827d6e9d38eca33b614790ded3 Mon Sep 17 00:00:00 2001 From: John Antoni Griffiths Date: Wed, 18 Jan 2012 14:18:09 -0500 Subject: [PATCH 3/5] add alias to view the standard out (puts) from any pow app --- plugins/pow/pow.plugin.zsh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/pow/pow.plugin.zsh b/plugins/pow/pow.plugin.zsh index 08e5cf62f..5ab55ff1f 100644 --- a/plugins/pow/pow.plugin.zsh +++ b/plugins/pow/pow.plugin.zsh @@ -47,4 +47,7 @@ kapow(){ touch ~/.pow/$vhost/tmp/restart.txt; [ $? -eq 0 ] && echo "pow: restarting $vhost.dev" } -compctl -W ~/.pow -/ kapow \ No newline at end of file +compctl -W ~/.pow -/ kapow + +# View the standard out (puts) from any pow app +alias kaput="tail -f ~/Library/Logs/Pow/apps/*" \ No newline at end of file From 3841da15d02e6d36310b9cc1ebd62502d0bf2135 Mon Sep 17 00:00:00 2001 From: John Antoni Griffiths Date: Wed, 18 Jan 2012 18:07:31 -0500 Subject: [PATCH 4/5] don't check for tmp dir --- plugins/pow/pow.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pow/pow.plugin.zsh b/plugins/pow/pow.plugin.zsh index 5ab55ff1f..0fbcf8c7b 100644 --- a/plugins/pow/pow.plugin.zsh +++ b/plugins/pow/pow.plugin.zsh @@ -43,7 +43,7 @@ kapow(){ return 1 fi - [ ! -d "~/.pow/${vhost}/tmp" ] && mkdir -p "~/.pow/$vhost/tmp" + # [ ! -d "~/.pow/${vhost}/tmp" ] && mkdir -p "~/.pow/$vhost/tmp" touch ~/.pow/$vhost/tmp/restart.txt; [ $? -eq 0 ] && echo "pow: restarting $vhost.dev" } From f9b4356e0ed9e95890ce79c982dd5481ba7803aa Mon Sep 17 00:00:00 2001 From: John Antoni Griffiths Date: Wed, 18 Jan 2012 18:36:11 -0500 Subject: [PATCH 5/5] bug : stop creating those ~ directories add powit command to symlink an app if it hasn't been already --- plugins/pow/pow.plugin.zsh | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/plugins/pow/pow.plugin.zsh b/plugins/pow/pow.plugin.zsh index 0fbcf8c7b..399a54cb0 100644 --- a/plugins/pow/pow.plugin.zsh +++ b/plugins/pow/pow.plugin.zsh @@ -34,6 +34,7 @@ rack_root_detect(){ [[ ${basedir} == "/" ]] && return 1 echo `basename $basedir | sed -E "s/.(com|net|org)//"` } + kapow(){ local vhost=$1 [ ! -n "$vhost" ] && vhost=$(rack_root_detect) @@ -43,11 +44,23 @@ kapow(){ return 1 fi - # [ ! -d "~/.pow/${vhost}/tmp" ] && mkdir -p "~/.pow/$vhost/tmp" + [ ! -d ~/.pow/${vhost}/tmp ] && mkdir -p ~/.pow/$vhost/tmp touch ~/.pow/$vhost/tmp/restart.txt; [ $? -eq 0 ] && echo "pow: restarting $vhost.dev" } compctl -W ~/.pow -/ kapow +powit(){ + local basedir=$(pwd) + local vhost=$1 + [ ! -n "$vhost" ] && vhost=$(rack_root_detect) + if [ ! -h ~/.pow/$vhost ] + then + echo "pow: Symlinking your app with pow. ${vhost}" + [ ! -d ~/.pow/${vhost} ] && ln -s $basedir ~/.pow/$vhost + return 1 + fi +} + # View the standard out (puts) from any pow app -alias kaput="tail -f ~/Library/Logs/Pow/apps/*" \ No newline at end of file +alias kaput="tail -f ~/Library/Logs/Pow/apps/*"