diff --git a/nvm.sh b/nvm.sh index 7d2bb1e..4ed0926 100644 --- a/nvm.sh +++ b/nvm.sh @@ -34,11 +34,30 @@ if [ -z "$NVM_NODEJS_ORG_MIRROR" ]; then export NVM_NODEJS_ORG_MIRROR="http://nodejs.org/dist" fi +# Traverse up in directory tree to find containing folder +nvm_find_up() { + local path + path=$PWD + while [ "$path" != "" ] && [ ! -f "$path/$1" ]; do + path=${path%/*} + done + echo "$path" +} + + +nvm_find_nvmrc() { + local dir="$(nvm_find_up '.nvmrc')" + if [ -e "$dir/.nvmrc" ]; then + echo "$dir/.nvmrc" + fi +} + # Obtain nvm version from rc file nvm_rc_version() { - if [ -e .nvmrc ]; then - NVM_RC_VERSION=`cat .nvmrc | head -n 1` - echo "Found .nvmrc files with version <$NVM_RC_VERSION>" + local NVMRC_PATH="$(nvm_find_nvmrc)" + if [ -e "$NVMRC_PATH" ]; then + NVM_RC_VERSION=`cat "$NVMRC_PATH" | head -n 1` + echo "Found '$NVMRC_PATH' with version <$NVM_RC_VERSION>" fi } diff --git "a/test/slow/nvm run/Running \"nvm run\" should pick up .nvmrc version" "b/test/slow/nvm run/Running \"nvm run\" should pick up .nvmrc version" index 181e3fc..d462488 100755 --- "a/test/slow/nvm run/Running \"nvm run\" should pick up .nvmrc version" +++ "b/test/slow/nvm run/Running \"nvm run\" should pick up .nvmrc version" @@ -6,7 +6,8 @@ die () { echo $@ ; exit 1; } . ../../../nvm.sh echo "0.10.7" > .nvmrc -[ "$(nvm run --version | tail -1)" = "v0.10.7" ] || die "`nvm run` failed to run with the .nvmrc version" -[ "$(nvm run --version | head -1)" = "Found .nvmrc files with version <0.10.7>" ] || die "`nvm run` failed to print out the \"found in .nvmrc\" message" +[ "$(nvm run --version | tail -1)" = "v0.10.7" ] || die "\`nvm run\` failed to run with the .nvmrc version" + +[ "$(nvm run --version | head -1)" = "Found '$PWD/.nvmrc' with version <0.10.7>" ] || die "\`nvm run\` failed to print out the \"found in .nvmrc\" message"