From: Colin Patrick McCabe Date: Sat, 8 Oct 2011 05:13:13 +0000 (-0700) Subject: Add boon X-Git-Url: http://club.cc.cmu.edu/~cmccabe/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=89bf1b08bbb45fa55d37d708f5aacbbdf2bc7885;p=cmccabe-bin Add boon Signed-off-by: Colin McCabe --- diff --git a/boon b/boon new file mode 100755 index 0000000..7faa332 --- /dev/null +++ b/boon @@ -0,0 +1,40 @@ +#!/bin/bash + +# +# boon +# +# This script searches all the ancestors of the current directory for a file +# named .boon. When it finds one, it sources it. +# Then it creates a new shell. +# +# The idea is to use this to manage environment variables based on paths. +# +# Colin Patrick McCabe +# + +die() { + echo $@ + exit 1 +} + +D=. +COUNT=0 +FOUND_BOON=0 +while true; do + if [ -x "${D}/.boon" ]; then + cat "${D}/.boon" + source "${D}/.boon" + FOUND_BOON=1 + fi + D="${D}/.." + COUNT=$(($COUNT+1)) + if [ $COUNT -gt 100 ]; then + if [ $FOUND_BOON -eq 0 ]; then + die "Error: couldn't find .boon" + else + # start a shell with our new environment + bash + fi + fi +done +