From cf3728c5aad9e94bf412ad22a5f311c95a75210e Mon Sep 17 00:00:00 2001 From: Ivan Povalyukhin Date: Sat, 30 May 2015 00:26:22 -0700 Subject: [PATCH 1/2] [pathmunge] added function to prevent duplicates in PATH variable --- lib/helpers.bash | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/helpers.bash b/lib/helpers.bash index 9c4c4dbc..c5ae9cd1 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -361,3 +361,21 @@ all_groups () cat $file | sort | uniq rm $file } + +if ! type pathmunge > /dev/null 2>&1 +then + function pathmunge () { + _about 'prevent duplicate directories in you PATH variable' + _group 'lib helpers' + _example 'pathmunge /path/to/dir is equivalent to PATH=/path/to/dir:$PATH' + _example 'pathmunge /path/to/dir after is equivalent to PATH=$PATH:/path/to/dir' + + if ! [[ $PATH =~ (^|:)$1($|:) ]] ; then + if [ "$2" = "after" ] ; then + export PATH=$PATH:$1 + else + export PATH=$1:$PATH + fi + fi + } +fi From 575551e42b4ea48c822aaea89bfd312d011e79a8 Mon Sep 17 00:00:00 2001 From: Ivan Povalyukhin Date: Sat, 30 May 2015 00:27:05 -0700 Subject: [PATCH 2/2] [pathmunge] fix duplicates in PATH variable for nginx and node plugins --- plugins/available/nginx.plugin.bash | 5 +---- plugins/available/node.plugin.bash | 6 ++---- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/plugins/available/nginx.plugin.bash b/plugins/available/nginx.plugin.bash index 8e8b7346..c540a23a 100644 --- a/plugins/available/nginx.plugin.bash +++ b/plugins/available/nginx.plugin.bash @@ -1,11 +1,8 @@ cite about-plugin about-plugin 'manage your nginx service' -# Set the path nginx export NGINX_PATH='/opt/nginx' - -# Add nginx to the path -export PATH=$PATH:$NGINX_PATH/sbin +pathmunge $NGINX_PATH/sbin after function nginx_reload() { about 'reload your nginx config' diff --git a/plugins/available/node.plugin.bash b/plugins/available/node.plugin.bash index 06b158e7..f0467cef 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 +pathmunge ./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` ]] && pathmunge $(npm config get prefix)/bin