From 47d5982ef8bd6e2e5ca5c8e0b108910b5937a291 Mon Sep 17 00:00:00 2001 From: Tim Caswell Date: Mon, 19 Apr 2010 10:22:28 -0500 Subject: [PATCH] Update to replace an old nvm path if it exists already in $PATH. --- nvm.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nvm.sh b/nvm.sh index 0f9c487..d3c9c34 100644 --- a/nvm.sh +++ b/nvm.sh @@ -78,8 +78,12 @@ nvm() nvm help return; fi - # TODO: Remove old nvm paths before adding this one - PATH="$NVM_DIR/$2/bin:$PATH" + if [[ $PATH == *$NVM_DIR/*/bin* ]]; then + PATH=${PATH%$NVM_DIR/*/bin*}$NVM_DIR/$2/bin${PATH#*$NVM_DIR/*/bin} + else + PATH="$NVM_DIR/$2/bin:$PATH" + fi + export PATH echo "Now using node $2" ;; "list" )