X-Git-Url: http://git.iain.cx/?p=profile.git;a=blobdiff_plain;f=.bash_profile;h=6fe0759a4575e80ef646ccf8a3a6cca7a9082ba0;hp=e905a8665a1222b89b75ea4e31e5398a187c0e05;hb=56d7364df9209bffe2ca58df0474e2555b75cb45;hpb=2da9ea6da645cdb26ca23d12f7f52c60351f3a4c diff --git a/.bash_profile b/.bash_profile index e905a86..6fe0759 100644 --- a/.bash_profile +++ b/.bash_profile @@ -1,7 +1,91 @@ -#echo "$(date +'%F %T'): pid: $$; ppid: $PPID; tty: $(tty); .bash_profile" >> ~/.nx/spam -if $(tty -s) || [ "${0:0:1}" = "-" ]; then - for i in ~/.profile.d/*.bashrc; do . $i; done; unset i - __ps1 +if [ -t 0 -o "${0:0:1}" = "-" -o "$1" = "force" ]; then + # Remember if nocaseglob was on. + shopt -q nocaseglob + nocg=$? + # Turn it off so we source stuff in the right order. + shopt -u nocaseglob + # Remember if nullglob was on. + shopt -q nullglob + nullglob=$? + # Turn it on so we can look in subdirectories. + shopt -s nullglob + + # Remember LC_ALL. + lc_all=$LC_ALL + # Turn it off to set case-sensitive matching + LC_ALL=C + + # 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 + for j in $profile_d/{,*/}$i; do + [ -e "$j" ] || continue + k="${j##$profile_d/}" + [ "${sourced/ $k /}" = "$sourced" ] || continue + . "$j" + sourced="$sourced $k " + break + done + done + + # Maybe turn nocaseglob back on. + [ $nocg = 0 ] && shopt -s nocaseglob + # Maybe turn nullglob back off. + [ $nullglob = 0 ] || shopt -u nullglob + + # Reset LC_ALL. + LC_ALL=$lc_all + + unset i j k d n dep deps profile_d path required unsorted sourced + unset lc_all nullglob nocg + + # Don't inherit failure from the last script. + true fi -#export IP01=.bash_profile -#export IP01BASH_PROFILE=.bash_profile