From 20b32fd07a42f220cb45adcc575dbd2e66a0ded8 Mon Sep 17 00:00:00 2001 From: Luiz Gonzaga dos Santos Filho Date: Mon, 5 Jun 2017 23:02:39 +0200 Subject: [PATCH 1/2] Prevent duplicate entries in $PATH. Fixes #690 --- zsh/0_path.zsh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/zsh/0_path.zsh b/zsh/0_path.zsh index db078f1e..04ed6c30 100644 --- a/zsh/0_path.zsh +++ b/zsh/0_path.zsh @@ -1,7 +1,14 @@ # path, the 0 in the filename causes this to load first -path=( - $path - $HOME/.yadr/bin - $HOME/.yadr/bin/yadr -) +# +# If you have duplicate entries on your PATH, run this command to fix it: +# PATH=$(echo "$PATH" | awk -v RS=':' -v ORS=":" '!a[$1]++{if (NR > 1) printf ORS; printf $a[$1]}') +pathAppend() { + # Only adds to the path if it's not already there + if ! echo $PATH | egrep -q "(^|:)$1($|:)" ; then + PATH=$PATH:$1 + fi +} + +pathAppend "$HOME/.yadr/bin" +pathAppend "$HOME/.yadr/bin/yadr" From 28e4f07eb97fb00942643e9e3cc779c3f06f8f47 Mon Sep 17 00:00:00 2001 From: Luiz Gonzaga dos Santos Filho Date: Tue, 6 Jun 2017 17:58:04 +0200 Subject: [PATCH 2/2] Run $PATH dedup command everytime --- zsh/0_path.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zsh/0_path.zsh b/zsh/0_path.zsh index 04ed6c30..050e67ac 100644 --- a/zsh/0_path.zsh +++ b/zsh/0_path.zsh @@ -1,7 +1,4 @@ # path, the 0 in the filename causes this to load first -# -# If you have duplicate entries on your PATH, run this command to fix it: -# PATH=$(echo "$PATH" | awk -v RS=':' -v ORS=":" '!a[$1]++{if (NR > 1) printf ORS; printf $a[$1]}') pathAppend() { # Only adds to the path if it's not already there @@ -10,5 +7,8 @@ pathAppend() { fi } +# Remove duplicate entries from PATH: +PATH=$(echo "$PATH" | awk -v RS=':' -v ORS=":" '!a[$1]++{if (NR > 1) printf ORS; printf $a[$1]}') + pathAppend "$HOME/.yadr/bin" pathAppend "$HOME/.yadr/bin/yadr"