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

Code before:
  local VERSION
  VERSION="$1"
  NPMLIST=$(nvm use "${VERSION}" >/dev/null && npm list -g --depth=0 2>/dev/null | command sed 1,1d | nvm_grep -v 'UNMET PEER DEPENDENCY')

  local INSTALLS
  INSTALLS=$(nvm_echo "${NPMLIST}" | command sed -e '/ -> / d' -e '/\(empty\)/ d' -e 's/^.* \(.*@[^ ]*\).*/\1/' -e '/^npm@[^ ]*.*$/ d' | command xargs)

  local LINKS
  LINKS="$(nvm_echo "${NPMLIST}" | command sed -n 's/.* -> \(.*\)/\1/ p')"

  nvm_echo "${INSTALLS} //// ${LINKS}"
}

nvm_npmrc_bad_news_bears() {
  local NVM_NPMRC
  NVM_NPMRC="${1-}"
  if [ -n "${NVM_NPMRC}" ] && [ -f "${NVM_NPMRC}" ] && nvm_grep -Ee '^(prefix|globalconfig) *=' <"${NVM_NPMRC}" >/dev/null; then
    return 0
  fi
  return 1
}

nvm_windows_drive_posix() {
  local location
  location=$(nvm_grep -iEe "^$1 " /etc/mtab 2>/dev/null | command awk '{ print $2 }')
  # Cygwin seems not to have /etc/mtab
  if [ -z "${location:-}" ]; then
    location=$(command mount | nvm_grep -iEe "^$1 " | command awk '{ print $3 }')
  fi
  nvm_echo "$location"
}

# args: path to check and transform if needed
nvm_ensure_posix_path() {
  if [ -z "${1-}" ]; then
    nvm_err "Need the location as first parameter"
    return 1
  fi
  local location
  location="$1"

  # If already posix path, just return it
  if [ "$(command printf '%s' "$location" | command cut -b 1)" = "/" ]; then
    nvm_echo "$location"
    return 0
  fi

  # If absolute path (eg. starting with C:)
  if command printf '%s' "$location" | command grep '^[a-zA-Z]:' >/dev/null 2>&1; then
    # Get drive letter, eg. C:
    local drive

Review comment (refactor):
Cygwin may not have `/etc/mtab` (and judging from some internet complaints, WSL might not always have it either), but AFAICT all three alternatives have `/proc/mounts`, with `/etc/mtab` just being a symlink when it exists.

Also, for both Cygwin and MSYS, the `cygpath` utility exists, but also `$(cd drive:/ ; pwd)` will do the trick since both Cygwin and MSYS support using Windows paths directly in at least bash and sh (that I tried).  I don't think WSL will handle that, though.  So probably, using /proc/mounts will do the trick for all three.

(Off topic: thanks for the work on this!  I've been using nvm on Cygwin for a very long time (5+ years), manually installing the binaries and tweaking the config files by hand to make it work.  It'll be nice not to have to do that any more!)

Code after:
      nvm_download -L https://npmjs.org/install.sh -o - | clean=yes sh
    fi
  fi
  return $?
}

nvm_match_version() {
  local NVM_IOJS_PREFIX
  NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
  local PROVIDED_VERSION
  PROVIDED_VERSION="$1"
  case "_${PROVIDED_VERSION}" in
    "_${NVM_IOJS_PREFIX}" | '_io.js')
      nvm_version "${NVM_IOJS_PREFIX}"
    ;;
    '_system')
      nvm_echo 'system'
    ;;
    *)
      nvm_version "${PROVIDED_VERSION}"
    ;;
  esac
}

nvm_npm_global_modules() {
  local NPMLIST
  local VERSION
  VERSION="$1"
  NPMLIST=$(nvm use "${VERSION}" >/dev/null && npm list -g --depth=0 2>/dev/null | command sed 1,1d | nvm_grep -v 'UNMET PEER DEPENDENCY')

  local INSTALLS
  INSTALLS=$(nvm_echo "${NPMLIST}" | command sed -e '/ -> / d' -e '/\(empty\)/ d' -e 's/^.* \(.*@[^ ]*\).*/\1/' -e '/^npm@[^ ]*.*$/ d' | command xargs)

  local LINKS
  LINKS="$(nvm_echo "${NPMLIST}" | command sed -n 's/.* -> \(.*\)/\1/ p')"

  nvm_echo "${INSTALLS} //// ${LINKS}"
}

nvm_npmrc_bad_news_bears() {
  local NVM_NPMRC
  NVM_NPMRC="${1-}"
  if [ -n "${NVM_NPMRC}" ] && [ -f "${NVM_NPMRC}" ] && nvm_grep -Ee '^(prefix|globalconfig) *=' <"${NVM_NPMRC}" >/dev/null; then
    return 0
  fi
  return 1
}

nvm_die_on_prefix() {
  local NVM_DELETE_PREFIX
  NVM_DELETE_PREFIX="${1-}"