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
Provenance
- Commit
74b36b0- Tree
122d41e- Author
Jordan Harband <ljharb@gmail.com>- Committer
Jordan Harband <ljharb@gmail.com>- Parent 1
080f214- Parent 2
7805492
5 files changed+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/sh2+3+mkdir ../../../v0.0.24+mkdir ../../../v0.0.205+6+. ../../../nvm.sh7+8+die () { echo $@ ; exit 1; }9+10+# The result should contain only the appropriate version numbers.11+12+nvm which 0.0.2 | grep "$NVM_DIR/v0.0.2/bin" > /dev/null13+if [ $? -ne 0 ]; then14+ die '"nvm which 0.0.2" did not contain the correct path'15+fi16+17+nvm which 0.0.20 | grep "$NVM_DIR/v0.0.20/bin" > /dev/null18+if [ $? -ne 0 ]; then19+ die '"nvm which 0.0.2" did not contain the correct path'20+fiadded:test/fast/Listing paths/Running "nvm which foo" should return a nonzero exit code when not found+6 added
1+ #!/bin/sh2+3+. ../../../nvm.sh4+5+nvm which nonexistent_version6+[ "$?" = "1" ]added:test/fast/Listing paths/teardown+2 added
1+rmdir ../../../v0.0.2 >/dev/null 2>&12+rmdir ../../../v0.0.20 >/dev/null 2>&1modified:nvm.sh+38 added
545 unmodified lines546 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 lines946 ;;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+ fi965+966+ 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+ fi978+979+ 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 DEST105 unmodified linesmodified:README.markdown+4 added
59 unmodified lines606162636465666768697071126 unmodified linesExpand all59 unmodified linesOr, you can run any arbitrary command in a subshell with the desired version of node:
nvm exec 0.10 node --version
You can also get the path to the executable to where it was installed:
nvm which 0.10
In place of a version pointer like "0.10", you can use the special default aliases "stable" and "unstable":
nvm install stable nvm install unstable126 unmodified linesExpand all