From c47bf603ed2e26b19e4b9738c6d3fd91ccd120cf Mon Sep 17 00:00:00 2001
From: hophacker <jiefeng.hopkins@gmail.com>
Date: Wed, 10 Apr 2019 18:34:12 +0800
Subject: [PATCH] Prevent duplicate entries in $PATH

---
 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 db078f1..04ed6c3 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"