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

13 lines
470 B
Bash
Raw Normal View History

2024-09-19 04:31:48 +00:00
#!/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