dotfiles/.config/shell/zshrc.d/9-deduplicate-path-variable.zsh

25 lines
534 B
Bash
Raw Normal View History

2019-07-24 05:33:28 +00:00
#!/bin/zsh
# shellcheck disable=SC2206
# shellcheck disable=SC2179
# shellcheck disable=SC2154
# In case a plugin adds a redundant path entry, remove duplicate entries
# from PATH
#
# This snippet is from Mislav Marohnić <mislav.marohnic@gmail.com>'s
# dotfiles repo at https://github.com/mislav/dotfiles
dedupe_path() {
typeset -a paths result
paths=($path)
while [[ ${#paths} -gt 0 ]]; do
p="${paths[1]}"
shift paths
[[ -z ${paths[(r)$p]} ]] && result+="$p"
done
export PATH=${(j+:+)result}
}
2019-07-24 05:33:28 +00:00
dedupe_path