Show host and session name in tmux status line.
[profile.git] / .bash_profile
old mode 100755 (executable)
new mode 100644 (file)
index 35cd3b8..b10aba7
@@ -1,52 +1,80 @@
-# $Id$
-for i in ~/.profile.d/*.bashrc; do . $i; done
-__ps1
+if tty -s || [ "${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
 
-unset XMODIFIERS #:-(
-export SSHTERM="urxvt"
-export SSHTERM_TITLE="-title"
-export SSHTERM_EXEC="-e"
+  # Remember LC_ALL.
+  lc_all=$LC_ALL
+  # Turn it off to set case-sensitive matching
+  LC_ALL=C
 
-if [ "$OSTYPE" = "cygwin" ]; then
-  shopt -s nocaseglob
-fi
+  # Force these to come before everything else.
+  required="OS.bashrc
+PATH.bashrc
+BECOME.bashrc"
 
-#[ "$TERM" = "xterm-color" ] && export TERM=xterm-xfree86
-export PATH=~/bin:"$PATH"
+  # Remember PATH so we can mangle it to find tsort and sed.
+  path="$PATH"
+  PATH=/usr/bin:/bin:/usr/ccs/bin
 
-function upload() {
-  if [ $# = 0 ]; then
-    echo usage: upload file [file...]
-    return 100
-  fi
-  pwd=$PWD/
-  pwd=${pwd##/home/iain/www/}
-  if echo $pwd | grep -q ^/; then
-    echo not rooted under /home/iain/www
-    unset pwd
-    return 111
-  fi
-# scp ${1+"$@"} 64.176.170.109:/home/iain/$pwd
-  lftp -c "open web1.viagold.net; cd $pwd; mput $@"
-  unset pwd
-}
-
-function download() {
-  if [ $# = 0 ]; then
-    echo usage: download file [file...]
-    return 100
+  # 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
-  pwd=$PWD/
-  pwd=${pwd##/home/iain/www/}
-  if echo $pwd | grep -q ^/; then
-    echo not rooted under /home/iain/www
-    unset pwd
-    return 111
+  sorted=$(echo "$deps" | tsort)
+  if [ -n "$sorted" ]; then
+    deps="$sorted"
+    unset sorted
   fi
-# scp ${1+"$@"} 64.176.170.109:/home/iain/$pwd
-  lftp -c "open web1.viagold.net; cd $pwd; mget $@"
-  unset pwd
-}
-alias debug='valgrind --leak-check=yes --show-reachable=yes --num-callers=5 --verbose'
+  deps="$required
+$deps"
+
+  # Restore PATH.
+  PATH="$path"
 
-eval `dircolors -b`
+  # 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
+
+  # Reset LC_ALL.
+  LC_ALL=$lc_all
+
+  unset i d n dep deps profile_d path required unsorted sourced
+  unset lc_all nocg
+
+  # Don't inherit failure from the last script.
+  true
+fi