Skip to content
Myr

Merge pull request #583 from danielb2/which

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Adds `nvm which`

authored by Jordan Harband · committed by Jordan Harband · parents 080f214, 7805492 · Browse files · 5 files+70 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+70 added−0 removed

  • tests:+28 added−0 removed
  • other:+42 added−0 removed

5 files+70 added−0 removed

added:test/fast/Listing paths/Running "nvm which 0.0.2" should display only version 0.0.2.+20 added
1#!/bin/sh23mkdir ../../../v0.0.24mkdir ../../../v0.0.2056. ../../../nvm.sh78die () { echo $@ ; exit 1; }910# The result should contain only the appropriate version numbers.1112nvm which 0.0.2 | grep "$NVM_DIR/v0.0.2/bin" > /dev/null13if [ $? -ne 0 ]; then14 die '"nvm which 0.0.2" did not contain the correct path'15fi1617nvm which 0.0.20 | grep "$NVM_DIR/v0.0.20/bin" > /dev/null18if [ $? -ne 0 ]; then19 die '"nvm which 0.0.2" did not contain the correct path'20fi
added:test/fast/Listing paths/Running "nvm which foo" should return a nonzero exit code when not found+6 added
1 #!/bin/sh23. ../../../nvm.sh45nvm which nonexistent_version6[ "$?" = "1" ]
added:test/fast/Listing paths/teardown+2 added
1rmdir ../../../v0.0.2 >/dev/null 2>&12rmdir ../../../v0.0.20 >/dev/null 2>&1
modified:nvm.sh+38 added
545 unmodified lines
546 echo " nvm alias <name> <version> Set an alias named <name> pointing to <version>"547 echo " nvm unalias <name> Deletes the alias named <name>"548 echo " nvm reinstall-packages <version> Reinstall global \`npm\` packages contained in <version> to current version"549 echo " nvm unload Unload \`nvm\` from shell"550 echo " nvm which [<version>] Display path to installed node version"551 echo552 echo "Example:"553 echo " nvm install v0.10.32 Install a specific version number"554 echo " nvm use 0.10 Use the latest available 0.10.x release"
391 unmodified lines
946 ;;947 "current" )948 nvm_version current949 ;;950 "which" )951 if [ $# -eq 1 ]; then952 nvm_rc_version953 if [ -n "$NVM_RC_VERSION" ]; then954 VERSION=$(nvm_version $NVM_RC_VERSION)955 fi956 elif [ "_$2" != '_system' ]; then957 VERSION="$(nvm_version "$2")"958 else959 VERSION="$2"960 fi961 if [ -z "$VERSION" ]; then962 nvm help963 return 127964 fi965966 if [ "_$VERSION" = '_system' ]; then967 if nvm_has_system_node >/dev/null 2>&1; then968 echo $(nvm use system && echo dirname $(which node))969 return970 else971 echo "System version of node not found." >&2972 return 127973 fi974 elif [ "_$VERSION" = "_∞" ]; then975 echo "The alias \"$2\" leads to an infinite loop. Aborting." >&2976 return 8977 fi978979 local NVM_VERSION_DIR980 NVM_VERSION_DIR="$(nvm_version_path "$VERSION")"981 if [ ! -d "$NVM_VERSION_DIR" ]; then982 echo "$VERSION version is not installed yet" >&2983 return 1984 fi985 echo $NVM_DIR/$VERSION/bin986 ;;987 "alias" )988 mkdir -p "$NVM_DIR/alias"989 if [ $# -le 2 ]; then990 local DEST
105 unmodified lines
modified:README.markdown+4 added