implements nvm which

master
Daniel Bretoi 2014-11-21 16:54:31 -08:00
parent afba4e08fd
commit 382c3aa85e
1 changed files with 35 additions and 0 deletions

35
nvm.sh
View File

@ -547,6 +547,7 @@ nvm() {
echo " nvm unalias <name> Deletes the alias named <name>"
echo " nvm copy-packages <version> Install global NPM packages contained in <version> to current version"
echo " nvm unload Unload NVM from shell"
echo " nvm which [<version>] 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