From 600d1c62deb6bbf0b4b8c82095e8075942e0eb0c Mon Sep 17 00:00:00 2001 From: Ivan Povalyukhin Date: Tue, 19 May 2015 18:12:54 -0700 Subject: [PATCH] fix duplicate entries in PATH; especially after executing reload command --- lib/helpers.bash | 9 +++++++++ plugins/available/node.plugin.bash | 6 ++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 9c4c4dbc..56abccbf 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -361,3 +361,12 @@ all_groups () cat $file | sort | uniq rm $file } + +function __append_uniq_path() { + declare -r new_path="${PATH}:${1}"; + if [[ $(echo $new_path | tr ":" "\n" | sort | uniq -d) != *"${1}"* ]]; then + export PATH="${PATH}:${1}"; + else + return 1; + fi +} diff --git a/plugins/available/node.plugin.bash b/plugins/available/node.plugin.bash index 06b158e7..9cc7b6ce 100644 --- a/plugins/available/node.plugin.bash +++ b/plugins/available/node.plugin.bash @@ -1,9 +1,7 @@ cite about-plugin about-plugin 'Node.js helper functions' -export PATH=./node_modules/.bin:$PATH +__append_uniq_path './node_modules/.bin' # Make sure the global npm prefix is on the path -[[ `which npm` ]] && export PATH=$(npm config get prefix)/bin:$PATH - - +[[ `which npm` ]] && __append_uniq_path "$(npm config get prefix)/bin"