X-Git-Url: http://git.iain.cx/?p=profile.git;a=blobdiff_plain;f=.profile.d%2FPATH.bashrc;h=38bb82558f7b760c423768c39e9415f08ad7a5c5;hp=a67a5ba508dd3d2e9f2300c190b2ae4a7e28af7a;hb=88bb919af5a85d1d7f791408058f9eee96140907;hpb=8fbd163e15300ebf2df0789cf0a9c66b415c5ce1 diff --git a/.profile.d/PATH.bashrc b/.profile.d/PATH.bashrc index a67a5ba..38bb825 100644 --- a/.profile.d/PATH.bashrc +++ b/.profile.d/PATH.bashrc @@ -14,7 +14,6 @@ PATH:bindirs C_INCLUDE_PATH:incdirs CPLUS_INCLUDE_PATH:@C_INCLUDE_PATH LD_LIBRARY_PATH:libdirs -LD_RUN_PATH:@PATH MANPATH:mandirs PKG_CONFIG_PATH:pkgdirs " @@ -122,6 +121,35 @@ function makepath() { eval "export $newpath='$path'" } +# Remove entries which are symlinks to other existing entries. +function canonicalisepath() { + local path="$1"; shift + local newpath= + + local JGD=$IFS + IFS=' +' + + local dirs=$(eval echo "\$$path") + local check=":$dirs:" + for dir in ${dirs//:/ +}; do + if [ -L "$dir" ]; then + # Is this a symlink to another entry? + local canon=$(readlink -f "$dir" 2>/dev/null) + if [ -n "$canon" ]; then + [ "${check/:$canon:/}" = "$check" ] || continue + fi + fi + + newpath="$newpath:$dir" + done + + IFS=$JGD + + eval "export $path='${newpath##:}'" +} + # Construct directory list, omitting nonexistent and undefined ones. dirs= for dir in "${SYSTEM:-@}/${ARCHITECTURE:-@}" "${SYSTEM:-@}" ""; do @@ -142,10 +170,10 @@ for path in $PATHS; do [ -e "$dir" ] || continue makepath "$var" "$dir" done + canonicalisepath "$var" else copypath "$var" "${source#@}" fi done - -unset DIR PATHS dir dirs path var source expandpath sanitisepath copypath makepath newpath addpath +unset DIR PATHS dir dirs path var source expandpath sanitisepath copypath makepath newpath addpath canonicalisepath