2019-07-24 05:33:28 +00:00
|
|
|
#!/bin/zsh
|
|
|
|
# shellcheck disable=SC2206
|
|
|
|
# shellcheck disable=SC2179
|
|
|
|
# shellcheck disable=SC2154
|
|
|
|
|
2019-02-18 16:55:05 +00:00
|
|
|
# In case a plugin adds a redundant path entry, remove duplicate entries
|
|
|
|
# from PATH
|
2019-07-24 09:32:04 +00:00
|
|
|
# from: https://unix.stackexchange.com/questions/40749/remove-duplicate-path-entries-with-awk-command
|
|
|
|
get_var() {
|
|
|
|
eval 'printf "%s\n" "${'"$1"'}"'
|
2019-02-18 16:55:05 +00:00
|
|
|
}
|
2019-07-24 09:32:04 +00:00
|
|
|
set_var() {
|
|
|
|
eval "$1=\"\$2\""
|
|
|
|
}
|
|
|
|
dedup_pathvar() {
|
|
|
|
pathvar_name="$1"
|
|
|
|
pathvar_value="$(get_var "$pathvar_name")"
|
|
|
|
deduped_path="$(perl -e 'print join(":",grep { not $seen{$_}++ } split(/:/, $ARGV[0]))' "$pathvar_value")"
|
|
|
|
set_var "$pathvar_name" "$deduped_path"
|
|
|
|
}
|
|
|
|
dedup_pathvar PATH
|
|
|
|
dedup_pathvar MANPATH
|