Fixed setting PROFILE_HOME when sourcing from relative path.
authorIain Patterson <me@iain.cx>
Wed, 4 Feb 2015 10:11:11 +0000 (10:11 +0000)
committerIain Patterson <me@iain.cx>
Wed, 4 Feb 2015 10:11:11 +0000 (10:11 +0000)
If .bash_profile was sourced from a relative path, eg ". profile/.rc",
PROFILE_HOME would not be canonicalised, resulting in many things
breaking when not run from the same directory the profile was initially
sourced from.

.bash_profile

index 6a1eaf8..6648c33 100644 (file)
@@ -3,6 +3,7 @@ if [ -t 0 -o "${0:0:1}" = "-" -o "$1" = "force" ]; then
   if [ -z "$PROFILE_HOME" ]; then
     # BASH_SOURCE isn't available prior to bash 3.
     profile_home=${BASH_SOURCE%/*}
+    [ -n "$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