X-Git-Url: http://git.iain.cx/?p=profile.git;a=blobdiff_plain;f=.bash_profile;h=9d6fa56569d8be192922ee4a742523f0cea74f26;hp=6fe0759a4575e80ef646ccf8a3a6cca7a9082ba0;hb=7cfa2e04af2ae08ec3890c116580b8cdfc0653f9;hpb=a35e8ca463e14772e3634291187553567bdc77f1 diff --git a/.bash_profile b/.bash_profile index 6fe0759..9d6fa56 100644 --- a/.bash_profile +++ b/.bash_profile @@ -1,4 +1,14 @@ if [ -t 0 -o "${0:0:1}" = "-" -o "$1" = "force" ]; then + # Set up PROFILE_HOME if called outside HOME. + if [ -z "$PROFILE_HOME" ]; then + # BASH_SOURCE isn't available prior to bash 3. + profile_home=${BASH_SOURCE%/*} + [ -n "$profile_home" -a -d "$profile_home" -a ! "${profile_home:0:1}" = "/" ] && profile_home=$(readlink -f "$profile_home" 2>/dev/null) + [ "$profile_home" = "$BASH_SOURCE" ] && profile_home=$PWD + [ "$profile_home" = "$HOME" ] || PROFILE_HOME=$profile_home + unset profile_home + fi + # Remember if nocaseglob was on. shopt -q nocaseglob nocg=$? @@ -25,12 +35,12 @@ BECOME.bashrc" PATH=/usr/bin:/bin:/usr/ccs/bin # Sort all scripts by dependencies. - profile_d=${PROFILE_HOME:-~}/.profile.d + PROFILE_D=${PROFILE_HOME:-~}/.profile.d deps= unsorted= - for i in $profile_d/{*/,}*.bashrc; do + for i in $PROFILE_D/{*/,}*.bashrc; do dep=$(sed -n 's/^##*[ ]*profile-required:[ ]*//p' "$i") - i="${i##$profile_d/}" + i="${i##$PROFILE_D/}" if [ -n "$dep" ]; then for d in $dep; do deps="$deps @@ -65,9 +75,9 @@ $deps" # Source them all in the right order. sourced= for i in $deps; do - for j in $profile_d/{,*/}$i; do + for j in $PROFILE_D/{,*/}$i; do [ -e "$j" ] || continue - k="${j##$profile_d/}" + k="${j##$PROFILE_D/}" [ "${sourced/ $k /}" = "$sourced" ] || continue . "$j" sourced="$sourced $k " @@ -83,7 +93,7 @@ $deps" # Reset LC_ALL. LC_ALL=$lc_all - unset i j k d n dep deps profile_d path required unsorted sourced + unset i j k d n dep deps path required unsorted sourced unset lc_all nullglob nocg # Don't inherit failure from the last script.