From 382c3aa85ec9e07a26438e6e4e3d7be5d6abcd55 Mon Sep 17 00:00:00 2001 From: Daniel Bretoi Date: Fri, 21 Nov 2014 16:54:31 -0800 Subject: [PATCH] implements nvm which --- nvm.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/nvm.sh b/nvm.sh index 969af37..d8dcfae 100644 --- a/nvm.sh +++ b/nvm.sh @@ -547,6 +547,7 @@ nvm() { echo " nvm unalias Deletes the alias named " echo " nvm copy-packages Install global NPM packages contained in to current version" echo " nvm unload Unload NVM from shell" + echo " nvm which [] Display path to installed node version" echo echo "Example:" echo " nvm install v0.10.24 Install a specific version number" @@ -949,6 +950,40 @@ nvm() { "current" ) nvm_version current ;; + "which" ) + INPUT=$2 + + if [ "_$2" != '_system' ]; then + VERSION="$(nvm_version "$INPUT")" + else + VERSION="$INPUT" + fi + if [ -z "$VERSION" ]; then + nvm help + return 127 + fi + + if [ "_$VERSION" = '_system' ]; then + if nvm_has_system_node && nvm deactivate >/dev/null 2>&1; then + echo $(dirname `which node`) + return + else + echo "System version of node not found." >&2 + return 127 + fi + elif [ "_$VERSION" = "_∞" ]; then + echo "The alias \"$2\" leads to an infinite loop. Aborting." >&2 + return 8 + fi + + local NVM_VERSION_DIR + NVM_VERSION_DIR="$(nvm_version_path "$VERSION")" + if [ ! -d "$NVM_VERSION_DIR" ]; then + echo "$VERSION version is not installed yet" >&2 + return 1 + fi + echo $NVM_DIR/$VERSION + ;; "alias" ) mkdir -p "$NVM_DIR/alias" if [ $# -le 2 ]; then