#!/usr/bin/env 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 exit 0 fi fi done