From 7fd6d05426f1aab24a0bc70ce5a1cab65f3cf1ef Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 19 Sep 2014 10:10:53 -0700 Subject: [PATCH] Instead of using expr to check if paths need cleaning, compare cleaned paths to original paths and export appropriately. --- nvm.sh | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/nvm.sh b/nvm.sh index 1c0845e..e543295 100644 --- a/nvm.sh +++ b/nvm.sh @@ -607,24 +607,30 @@ nvm() { ;; "deactivate" ) - if [ `expr "$PATH" : ".*$NVM_DIR/.*/bin.*"` != 0 ] ; then - export PATH=`nvm_strip_path "$PATH" "/bin"` + local NEWPATH + NEWPATH="$(nvm_strip_path "$PATH" "/bin")" + if [ "$PATH" = "$NEWPATH" ]; then + echo "Could not find $NVM_DIR/*/bin in \$PATH" >&2 + else + export PATH="$NEWPATH" hash -r echo "$NVM_DIR/*/bin removed from \$PATH" - else - echo "Could not find $NVM_DIR/*/bin in \$PATH" >&2 fi - if [ `expr "$MANPATH" : ".*$NVM_DIR/.*/share/man.*"` != 0 ] ; then - export MANPATH=`nvm_strip_path "$MANPATH" "/share/man"` - echo "$NVM_DIR/*/share/man removed from \$MANPATH" - else + + NEWPATH="$(nvm_strip_path "$MANPATH" "/share/man")" + if [ "$MANPATH" = "$NEWPATH" ]; then echo "Could not find $NVM_DIR/*/share/man in \$MANPATH" >&2 - fi - if [ `expr "$NODE_PATH" : ".*$NVM_DIR/.*/lib/node_modules.*"` != 0 ] ; then - export NODE_PATH=`nvm_strip_path "$NODE_PATH" "/lib/node_modules"` - echo "$NVM_DIR/*/lib/node_modules removed from \$NODE_PATH" else + export MANPATH="$NEWPATH" + echo "$NVM_DIR/*/share/man removed from \$MANPATH" + fi + + NEWPATH="$(nvm_strip_path "$NODE_PATH" "/lib/node_modules")" + if [ "$NODE_PATH" = "$NEWPATH" ]; then echo "Could not find $NVM_DIR/*/lib/node_modules in \$NODE_PATH" >&2 + else + export NODE_PATH="$NEWPATH" + echo "$NVM_DIR/*/lib/node_modules removed from \$NODE_PATH" fi ;; "use" )