X-Git-Url: http://git.iain.cx/?p=profile.git;a=blobdiff_plain;f=.bash_profile;h=b10aba7c53d96f2b1885dce6d7bbe7883da40d94;hp=6c93ffe524ac50a885edece07537155c1fe22723;hb=4fcf9cd7282d42387e839ccc329edce4dc32e78b;hpb=fbb8103d9b90c369b770286ea49b99ecb7352d36 diff --git a/.bash_profile b/.bash_profile index 6c93ffe..b10aba7 100644 --- a/.bash_profile +++ b/.bash_profile @@ -1,4 +1,4 @@ -if $(tty -s) || [ "${0:0:1}" = "-" -o "$1" = "force" ]; then +if tty -s || [ "${0:0:1}" = "-" -o "$1" = "force" ]; then # Remember if nocaseglob was on. shopt -q nocaseglob nocg=$? @@ -10,8 +10,61 @@ if $(tty -s) || [ "${0:0:1}" = "-" -o "$1" = "force" ]; then # Turn it off to set case-sensitive matching LC_ALL=C - # Source all scripts. - for i in ~/.profile.d/*.bashrc; do . "$i"; done; unset i + # Force these to come before everything else. + required="OS.bashrc +PATH.bashrc +BECOME.bashrc" + + # Remember PATH so we can mangle it to find tsort and sed. + path="$PATH" + PATH=/usr/bin:/bin:/usr/ccs/bin + + # Sort all scripts by dependencies. + profile_d=${PROFILE_HOME:-~}/.profile.d + deps= + unsorted= + for i in $profile_d/*.bashrc; do + dep=$(sed -n 's/^##*[ ]*profile-required:[ ]*//p' "$i") + i="${i##$profile_d/}" + if [ -n "$dep" ]; then + for d in $dep; do + deps="$deps +$d $i" + done + else + unsorted="$unsorted +$i" + fi + done + + deps="$deps$unsorted" + + # Avoid odd number of tokens for tsort. + n=$(echo "$deps" | wc -w) + if [ $((n%2)) = 1 ]; then + deps="$deps +${deps##* +}" + fi + sorted=$(echo "$deps" | tsort) + if [ -n "$sorted" ]; then + deps="$sorted" + unset sorted + fi + deps="$required +$deps" + + # Restore PATH. + PATH="$path" + + # Source them all in the right order. + sourced= + for i in $deps; do + [ -e "$profile_d/$i" ] || continue + [ "${sourced/ $i /}" = "$sourced" ] || continue + . "$profile_d/$i" + sourced="$sourced $i " + done # Maybe turn nocaseglob back on. [ $nocg = 0 ] && shopt -s nocaseglob @@ -19,6 +72,9 @@ if $(tty -s) || [ "${0:0:1}" = "-" -o "$1" = "force" ]; then # Reset LC_ALL. LC_ALL=$lc_all + unset i d n dep deps profile_d path required unsorted sourced unset lc_all nocg - __ps1 + + # Don't inherit failure from the last script. + true fi