Merge pull request #415 from koenpunt/fix-path-concat

utility method for append path, fixes #414
master
Jordan Harband 2014-05-08 10:27:17 -07:00
commit 4cd0b078d0
2 changed files with 30 additions and 4 deletions

16
nvm.sh
View File

@ -101,6 +101,14 @@ nvm_strip_path() {
echo "$1" | sed -e "s#$NVM_DIR/[^/]*$2[^:]*:##g" -e "s#:$NVM_DIR/[^/]*$2[^:]*##g" -e "s#$NVM_DIR/[^/]*$2[^:]*##g" echo "$1" | sed -e "s#$NVM_DIR/[^/]*$2[^:]*:##g" -e "s#:$NVM_DIR/[^/]*$2[^:]*##g" -e "s#$NVM_DIR/[^/]*$2[^:]*##g"
} }
nvm_prepend_path() {
if [ -z "$1" ]; then
echo "$2"
else
echo "$2:$1"
fi
}
nvm_binary_available() { nvm_binary_available() {
# binaries started with node 0.8.6 # binaries started with node 0.8.6
local MINIMAL="0.8.6" local MINIMAL="0.8.6"
@ -478,18 +486,18 @@ nvm() {
# Strip other version from PATH # Strip other version from PATH
PATH=`nvm_strip_path "$PATH" "/bin"` PATH=`nvm_strip_path "$PATH" "/bin"`
# Prepend current version # Prepend current version
PATH="$NVM_DIR/$VERSION/bin:$PATH" PATH=`nvm_prepend_path "$PATH" "$NVM_DIR/$VERSION/bin"`
if [ -z "$MANPATH" ]; then if [ -z "$MANPATH" ]; then
MANPATH=$(manpath) MANPATH=$(manpath)
fi fi
# Strip other version from MANPATH # Strip other version from MANPATH
MANPATH=`nvm_strip_path "$MANPATH" "/share/man"` MANPATH=`nvm_strip_path "$MANPATH" "/share/man"`
# Prepend current version # Prepend current version
MANPATH="$NVM_DIR/$VERSION/share/man:$MANPATH" MANPATH=`nvm_prepend_path "$MANPATH" "$NVM_DIR/$VERSION/share/man"`
# Strip other version from NODE_PATH # Strip other version from NODE_PATH
NODE_PATH=`nvm_strip_path "$NODE_PATH" "/lib/node_modules"` NODE_PATH=`nvm_strip_path "$NODE_PATH" "/lib/node_modules"`
# Prepend current version # Prepend current version
NODE_PATH="$NVM_DIR/$VERSION/lib/node_modules:$NODE_PATH" NODE_PATH=`nvm_prepend_path "$NODE_PATH" "$NVM_DIR/$VERSION/lib/node_modules"`
export PATH export PATH
hash -r hash -r
export MANPATH export MANPATH
@ -535,7 +543,7 @@ nvm() {
return; return;
fi fi
RUN_NODE_PATH=`nvm_strip_path "$NODE_PATH" "/lib/node_modules"` RUN_NODE_PATH=`nvm_strip_path "$NODE_PATH" "/lib/node_modules"`
RUN_NODE_PATH="$NVM_DIR/$VERSION/lib/node_modules:$NODE_PATH" RUN_NODE_PATH=`nvm_prepend_path "$NODE_PATH" "$NVM_DIR/$VERSION/lib/node_modules"`
echo "Running node $VERSION" echo "Running node $VERSION"
NODE_PATH=$RUN_NODE_PATH $NVM_DIR/$VERSION/bin/node "$@" NODE_PATH=$RUN_NODE_PATH $NVM_DIR/$VERSION/bin/node "$@"
;; ;;

View File

@ -0,0 +1,18 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
TEST_PATH=/usr/bin:/usr/local/bin
NEW_PATH=`nvm_prepend_path "$TEST_PATH" "$NVM_DIR/v0.2.5/bin"`
[ "$NEW_PATH" = "$NVM_DIR/v0.2.5/bin:/usr/bin:/usr/local/bin" ] || die "Not correctly prepended: $STRIPPED_PATH "
EMPTY_PATH=
NEW_PATH=`nvm_prepend_path "$EMPTY_PATH" "$NVM_DIR/v0.2.5/bin"`
[ "$NEW_PATH" = "$NVM_DIR/v0.2.5/bin" ] || die "Not correctly prepended: $STRIPPED_PATH "