From 3157d132297d8c2eee65a3a78a14f4252334c9ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Inge=20J=C3=B8rgensen?= Date: Wed, 7 Sep 2011 15:19:14 +0200 Subject: [PATCH 1/2] Uses the updated kapow script for restarting pow apps kapow now defaults to the current Rack application if none is given. --- plugins/pow/pow.plugin.zsh | 60 +++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/plugins/pow/pow.plugin.zsh b/plugins/pow/pow.plugin.zsh index 6b2a6f2be..e0284c1f4 100644 --- a/plugins/pow/pow.plugin.zsh +++ b/plugins/pow/pow.plugin.zsh @@ -1,10 +1,56 @@ # Thanks 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 -} +# https://gist.github.com/1019777 +# Restart a rack app running under pow +# http://pow.cx/ +# +# Adds a kapow command that will restart an app +# +# $ kapow myapp +# +# Supports command completion. +# +# If you are not already using completion you might need to enable it with +# +# autoload -U compinit compinit +# +# Changes: +# +# 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 + +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 + +# View the standard out (puts) from any pow app +alias kaput="tail -f ~/Library/Logs/Pow/apps/*" \ No newline at end of file From 29ed9b29866ccdcbc2f63f312bc5d4859e60c3be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Inge=20J=C3=B8rgensen?= Date: Wed, 7 Sep 2011 15:43:47 +0200 Subject: [PATCH 2/2] powinit command symlinks apps to the pow dir --- plugins/pow/pow.plugin.zsh | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/plugins/pow/pow.plugin.zsh b/plugins/pow/pow.plugin.zsh index e0284c1f4..a4c9adac2 100644 --- a/plugins/pow/pow.plugin.zsh +++ b/plugins/pow/pow.plugin.zsh @@ -1,9 +1,6 @@ # Thanks to Christopher Sexton # https://gist.github.com/1019777 -# Restart a rack app running under pow -# http://pow.cx/ -# # Adds a kapow command that will restart an app # # $ kapow myapp @@ -35,11 +32,12 @@ rack_root_detect(){ builtin cd $orgdir 2>/dev/null [[ ${basedir} == "/" ]] && return 1 - echo `basename $basedir | sed -E "s/.(com|net|org)//"` + echo $basedir } + kapow(){ local vhost=$1 - [ ! -n "$vhost" ] && vhost=$(rack_root_detect) + [ ! -n "$vhost" ] && vhost=$(basename `rack_root_detect` | sed -E "s/.(com|net|org)//") if [ ! -h ~/.pow/$vhost ] then echo "pow: This domain isn’t set up yet. Symlink your application to ${vhost} first." @@ -50,6 +48,33 @@ kapow(){ touch ~/.pow/$vhost/tmp/restart.txt; [ $? -eq 0 ] && echo "pow: restarting $vhost.dev" } + +# The powinit command symlinks a dir to ~/.pow +# +# $ powinit /path/to/myapp +# +# powinit alone uses the working dir: +# +# $ powinit + +powinit(){ + local full_path=$1 + [ -n "$full_path" ] && full_path=$(echo $full_path(:A)) + [ ! -n "$full_path" ] && full_path=$(rack_root_detect) + if [ ! -n "$full_path" ] + then + echo "pow: Not a rack app" + return 1 + fi + local vhost=$(basename $full_path | sed -E "s/.(com|net|org)//") + if [ -h ~/.pow/$vhost ] + then + echo "pow: This domain is already set up. Remove the symlink in ~/.pow to reconfigure." + return 1 + fi + ln -s $full_path ~/.pow/$vhost + echo "pow: Application set up on http://$vhost.dev" +} compctl -W ~/.pow -/ kapow # View the standard out (puts) from any pow app