Repository: nvm-sh/nvm
File: nvm.sh (Shell)

Code before:
  pathdir=$(dirname "${node_path}")
  while [ "${pathdir}" != "" ] && [ "${pathdir}" != "." ] && [ "${pathdir}" != "/" ] && [ "${pathdir}" != "${tree}" ]; do
    pathdir=$(dirname "${pathdir}")
  done
  [ "${pathdir}" = "${tree}" ]
}

# 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
  nvm_echo "${path_}"
}


nvm_find_nvmrc() {
  local legacy_nvm_dir
  legacy_nvm_dir="$(nvm_find_up '.nvmrc')"
  if [ -e "${legacy_nvm_dir}/.nvmrc" ]; then
    nvm_echo "${legacy_nvm_dir}/.nvmrc"
  fi
  if [ -e "${XDG_CONFIG_HOME}/nvm/.nvmrc" ]; then
    nvm_echo "${XDG_CONFIG_HOME}/nvm/.nvmrc"
  fi
}

# Obtain nvm version from rc file
nvm_rc_version() {
  export NVM_RC_VERSION=''
  local NVMRC_PATH
  NVMRC_PATH="$(nvm_find_nvmrc)"
  if [ ! -e "${NVMRC_PATH}" ]; then
    nvm_err "No .nvmrc file found"
    return 1
  fi
  NVM_RC_VERSION="$(command head -n 1 "${NVMRC_PATH}" | command tr -d '\r')" || command printf ''
  if [ ! -n "${NVM_RC_VERSION}" ]; then
    nvm_err "Warning: empty .nvmrc file found at \"${NVMRC_PATH}\""
    return 2
  fi
  nvm_echo "Found '${NVMRC_PATH}' with version <${NVM_RC_VERSION}>"
}

nvm_clang_version() {
  clang --version | command awk '{ if ($2 == "version") print $3; else if ($3 == "version") print $4 }' | command sed 's/-.*$//g'
}

nvm_curl_version() {

Review comment (suggestion):
this will print out two lines if both locations exist.

I'm not actually sure why this is being changed; `.nvmrc` doesn't work currently inside `$NVM_DIR` when it's `$HOME/.nvm`; i'm not sure why it'd start working inside the XDG folder. If you want a global default, you'd do `nvm alias default whatever`.

Code after:
  pathdir=$(dirname "${node_path}")
  while [ "${pathdir}" != "" ] && [ "${pathdir}" != "." ] && [ "${pathdir}" != "/" ] && [ "${pathdir}" != "${tree}" ]; do
    pathdir=$(dirname "${pathdir}")
  done
  [ "${pathdir}" = "${tree}" ]
}

# 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
  nvm_echo "${path_}"
}


nvm_find_nvmrc() {
  local dir
  dir="$(nvm_find_up '.nvmrc')"
  if [ -e "${dir}/.nvmrc" ]; then
    nvm_echo "${dir}/.nvmrc"
  fi
}

# Obtain nvm version from rc file
nvm_rc_version() {
  export NVM_RC_VERSION=''
  local NVMRC_PATH
  NVMRC_PATH="$(nvm_find_nvmrc)"
  if [ ! -e "${NVMRC_PATH}" ]; then
    nvm_err "No .nvmrc file found"
    return 1
  fi
  NVM_RC_VERSION="$(command head -n 1 "${NVMRC_PATH}" | command tr -d '\r')" || command printf ''
  if [ ! -n "${NVM_RC_VERSION}" ]; then
    nvm_err "Warning: empty .nvmrc file found at \"${NVMRC_PATH}\""
    return 2
  fi
  nvm_echo "Found '${NVMRC_PATH}' with version <${NVM_RC_VERSION}>"
}

nvm_clang_version() {
  clang --version | command awk '{ if ($2 == "version") print $3; else if ($3 == "version") print $4 }' | command sed 's/-.*$//g'
}

nvm_curl_version() {
  curl -V | command awk '{ if ($1 == "curl") print $2 }' | command sed 's/-.*$//g'
}