dotfiles/_home/private_dot_config/sz.env/PATH_zz_cleanup.env

16 lines
514 B
Bash

#!/usr/bin/env -S sh -c 'echo "Not a user script. source(aka .) only"'
# Remove duplicates from PATH
OLDPATH="$PATH"; NEWPATH=""; colon=""
while [ "${OLDPATH#*:}" != "$OLDPATH" ]; do
entry="${OLDPATH%%:*}"; search=":${OLDPATH#*:}:"
[ "${search#*:"$entry":}" = "$search" ] && [[ -d $entry ]] && NEWPATH="$NEWPATH$colon$entry" && colon=:
OLDPATH="${OLDPATH#*:}"
done
NEWPATH="$NEWPATH:$OLDPATH"
export PATH="$NEWPATH"
unset NEWPATH OLDPATH colon entry search
[[ -n "${DBG}" ]] && echo "${PATH//:/\n}"