use sed for *PATH stripping

master
Koen Punt 2014-05-05 21:43:22 +02:00
parent 29f582611b
commit 3d9c1d7852
2 changed files with 16 additions and 18 deletions

30
nvm.sh
View File

@ -424,20 +424,20 @@ nvm() {
;;
"deactivate" )
if [ `expr "$PATH" : ".*$NVM_DIR/.*/bin.*"` != 0 ] ; then
export PATH=${PATH%$NVM_DIR/*/bin*}${PATH#*$NVM_DIR/*/bin:}
export PATH=`echo $PATH | sed -E "s#$NVM_DIR/[^/]*/bin[^:]*(:)?##g"`
hash -r
echo "$NVM_DIR/*/bin removed from \$PATH"
else
echo "Could not find $NVM_DIR/*/bin in \$PATH"
fi
if [ `expr "$MANPATH" : ".*$NVM_DIR/.*/share/man.*"` != 0 ] ; then
export MANPATH=${MANPATH%$NVM_DIR/*/share/man*}${MANPATH#*$NVM_DIR/*/share/man:}
export MANPATH=`echo $MANPATH | sed -E "s#$NVM_DIR/[^/]*/share/man[^:]*(:)?##g"`
echo "$NVM_DIR/*/share/man removed from \$MANPATH"
else
echo "Could not find $NVM_DIR/*/share/man in \$MANPATH"
fi
if [ `expr "$NODE_PATH" : ".*$NVM_DIR/.*/lib/node_modules.*"` != 0 ] ; then
export NODE_PATH=${NODE_PATH%$NVM_DIR/*/lib/node_modules*}${NODE_PATH#*$NVM_DIR/*/lib/node_modules:}
export NODE_PATH=`echo $NODE_PATH | sed -E "s#$NVM_DIR/[^/]*/lib/node_modules[^:]*(:)?##g"`
echo "$NVM_DIR/*/lib/node_modules removed from \$NODE_PATH"
else
echo "Could not find $NVM_DIR/*/lib/node_modules in \$NODE_PATH"
@ -468,24 +468,23 @@ nvm() {
return 1
fi
if [ `expr "$PATH" : ".*$NVM_DIR/.*/bin"` != 0 ]; then
PATH=${PATH%$NVM_DIR/*/bin*}$NVM_DIR/$VERSION/bin${PATH#*$NVM_DIR/*/bin}
else
PATH="$NVM_DIR/$VERSION/bin:$PATH"
# Strip other version from PATH
PATH=`echo $PATH | sed -E "s#$NVM_DIR/[^/]*/bin[^:]*(:)?##g"`
fi
PATH="$NVM_DIR/$VERSION/bin:$PATH"
if [ -z "$MANPATH" ]; then
MANPATH=$(manpath)
fi
MANPATH=${MANPATH#*$NVM_DIR/*/man:}
if [ `expr "$MANPATH" : ".*$NVM_DIR/.*/share/man"` != 0 ]; then
MANPATH=${MANPATH%$NVM_DIR/*/share/man*}$NVM_DIR/$VERSION/share/man${MANPATH#*$NVM_DIR/*/share/man}
else
# Strip other version from MANPATH
MANPATH=`echo $MANPATH | sed -E "s#$NVM_DIR/[^/]*/share/man[^:]*(:)?##g"`
fi
MANPATH="$NVM_DIR/$VERSION/share/man:$MANPATH"
fi
if [ `expr "$NODE_PATH" : ".*$NVM_DIR/.*/lib/node_modules.*"` != 0 ]; then
NODE_PATH=${NODE_PATH%$NVM_DIR/*/lib/node_modules*}$NVM_DIR/$VERSION/lib/node_modules${NODE_PATH#*$NVM_DIR/*/lib/node_modules}
else
NODE_PATH="$NVM_DIR/$VERSION/lib/node_modules:$NODE_PATH"
# Strip other version from NODE_PATH
NODE_PATH=`echo $NODE_PATH | sed -E "s#$NVM_DIR/[^/]*/lib/node_modules[^:]*(:)?##g"`
fi
NODE_PATH="$NVM_DIR/$VERSION/lib/node_modules:$NODE_PATH"
export PATH
hash -r
export MANPATH
@ -531,10 +530,9 @@ nvm() {
return;
fi
if [ `expr "$NODE_PATH" : ".*$NVM_DIR/.*/lib/node_modules.*"` != 0 ]; then
RUN_NODE_PATH=${NODE_PATH%$NVM_DIR/*/lib/node_modules*}$NVM_DIR/$VERSION/lib/node_modules${NODE_PATH#*$NVM_DIR/*/lib/node_modules}
else
RUN_NODE_PATH="$NVM_DIR/$VERSION/lib/node_modules:$NODE_PATH"
RUN_NODE_PATH=`echo $NODE_PATH | sed -E "s#$NVM_DIR/[^/]*/lib/node_modules[^:]*(:)?##g"`
fi
RUN_NODE_PATH="$NVM_DIR/$VERSION/lib/node_modules:$NODE_PATH"
echo "Running node $VERSION"
NODE_PATH=$RUN_NODE_PATH $NVM_DIR/$VERSION/bin/node "$@"
;;

View File

@ -8,7 +8,7 @@ die () { echo $@ ; exit 1; }
. ../../nvm.sh
nvm use v0.2.3 &&
[ `expr $PATH : ".*v0.2.3/.*/bin"` != 0 ] || die "Failed to activate v0.2.3"
[ `expr $PATH : ".*v0.2.3/.*/bin"` != 0 ] && [ `expr $NODE_PATH : ".*v0.2.3/.*/lib/node_modules"` != 0 ] || die "Failed to activate v0.2.3"
nvm deactivate &&
[ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] || die "Failed to deactivate v0.2.3"
[ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] && [ `expr $NODE_PATH : ".*v0.2.3/.*/lib/node_modules"` = 0 ] || die "Failed to deactivate v0.2.3"