From 1810d36fa5a4eede8fd6faccf769f6932ec62e57 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Thu, 5 Oct 2017 16:24:32 -0400 Subject: [PATCH] Check for both files then up to the parent --- nvm.sh | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/nvm.sh b/nvm.sh index 76b7147..1eefa28 100644 --- a/nvm.sh +++ b/nvm.sh @@ -274,24 +274,26 @@ nvm_tree_contains_path() { # Traverse up in directory tree to find containing folder nvm_find_up() { local path + local file path="${PWD}" - while [ "${path}" != "" ] && [ ! -f "${path}/${1-}" ]; do - path=${path%/*} + + # Iterate through the multiple files + while [ $# -ne 0 ]; do + # Look for files in turn in this path + while [ "${path}" != "" ]; do + # Is the file here? + if [ ! -f "${path}/${1}" ]; then + file="${path}/${1}" + nvm_echo $file + break 2 + fi + done + shift done - nvm_echo "${path}" } nvm_find_nvmrc() { - local dir - dir="$(nvm_find_up '.nvmrc')" - if [ -e "${dir}/.nvmrc" ]; then - nvm_echo "${dir}/.nvmrc" - else - dir="$(nvm_find_up '.node-version')" - if [ -e "${dir}/.node-version" ]; then - nvm_echo "${dir}/.node-version" - fi - fi + nvm_echo "$(nvm_find_up '.nvmrc' '.node-version')" } nvm_rc_version() { @@ -302,12 +304,13 @@ nvm_rc_version() { nvm_err "No .nvmrc or .node-version file found" return 1 fi + NVMRC_BASENAME="$(command basename "$NVMRC_PATH")" read -r NVM_RC_VERSION < "${NVMRC_PATH}" || printf '' if [ ! -n "${NVM_RC_VERSION}" ]; then - nvm_err "Warning: empty nvm file found at \"${NVMRC_PATH}\"" + nvm_err "Warning: empty \"${NVMRC_BASENAME}\" file found at \"${NVMRC_PATH}\"" return 2 fi - nvm_echo "Found '${NVMRC_PATH}' with version <${NVM_RC_VERSION}>" + nvm_echo "Found \"${NVMRC_BASENAME}\" with version <${NVM_RC_VERSION}>" } nvm_clang_version() {