X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=.profile.d%2FPATH.bashrc;h=0b82245160706099a2ecb673f6e11bd5d550b489;hb=7b6dd8b88884f5a74776de2a4af4142b11ee6fef;hp=ab57aaabca30c6e20d9d61443abe86797a6fa86d;hpb=0022b1a8c3238ee7350d19b93ac9816e66405cc3;p=profile.git diff --git a/.profile.d/PATH.bashrc b/.profile.d/PATH.bashrc index ab57aaa..0b82245 100644 --- a/.profile.d/PATH.bashrc +++ b/.profile.d/PATH.bashrc @@ -6,7 +6,7 @@ # # Location of the XXXdirs files. -DIR="$HOME/.PATH" +DIR=${PROFILE_HOME:-~}/.PATH # Paths to set and the file to get them from @variable to copy from. PATHS=" @@ -49,6 +49,19 @@ function copypath() { [ -z "$path" ] || eval "export $newpath='$path'" } +# Helper. +function addpath() { + local path="$1"; shift + local dir="$1"; shift + + dir=$(eval echo "$dir") + if [ -d "$dir" ]; then + echo "$path:$dir" + else + echo "$path" + fi +} + # Set a path from directories. function makepath() { local newpath="$1"; shift @@ -61,10 +74,11 @@ function makepath() { # Read them. local path= while read dir; do - local dir=$(eval echo "$dir") - [ -d "$dir" ] || continue - - path="$path:$dir" + path=$(addpath "$path" "$dir") + if [ -n "$PROFILE_HOME" -a ! "${dir#\$HOME}" = "$dir" ]; then + dir="$PROFILE_HOME${dir#\$HOME}" + path=$(addpath "$path" "$dir") + fi done < "$dirs" # Restore IFS. @@ -115,4 +129,4 @@ for path in $PATHS; do done -unset DIR PATHS dir dirs path var source sanitisepath copypath makepath newpath setpaths +unset DIR PATHS dir dirs path var source sanitisepath copypath makepath newpath addpath