Add boon
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Sat, 8 Oct 2011 05:13:13 +0000 (22:13 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 11 Oct 2011 18:16:23 +0000 (11:16 -0700)
Signed-off-by: Colin McCabe <cmccabe@alumni.cmu.edu>

boon [new file with mode: 0755]

diff --git a/boon b/boon
new file mode 100755 (executable)
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
+