Created
July 12, 2021 13:08
-
-
Save anddam/88a37a69722446e1440d129df7ea4ceb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -- | |
# example of .path_dirs file: | |
# /home/anddam/bin | |
# /home/anddam/.local/bin | |
{ | |
# This 'config' should probably be found more nicely than this. | |
cat "${1:-$HOME/.path_dirs}" | |
IFS=: | |
# Wordsplitting is purposefully used here over a colon. PATH is | |
# guaranteed to be separated by colons so this is reliable. | |
# shellcheck disable=SC2086 | |
printf '%s\n' $PATH | |
} | { | |
while read -r dir; do | |
# printf "dir=%s\n" $dir | |
[ -d "$dir" ] && set -- "$@" "$dir" | |
done | |
# printf 'arg=%s\n' "$arg" | |
for arg; do | |
# printf 'arg=%s\n' "$arg" | |
case :$tmp: in | |
*:$arg:*) ;; | |
*) path=${path:+$path:}$arg | |
esac | |
tmp=${tmp:+$tmp:}$arg | |
done | |
printf '%s\n' "$path" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment