Added nvm standalone shell script. Therefore added check if current node executable is wihtin the auto detected NVM_DIR. If not it will return 'N/A'. So it will not display any 'current version' as long as there is no installed node version within this current NVM_DIR. There is also a 'which', 'root' and 'bin' command. 'which' returns the absolute path to the currently used node version. 'root' prints the absolute path to root path of the currently used node version - the path where the bin and lib dir is. And 'bin' prints the absolute path to the 'bin' directory of the currently used node version.

This commit is contained in:
Thomas Fritz 2012-08-23 17:47:57 +02:00
parent 04652a5090
commit 6686b65a0f
2 changed files with 51 additions and 13 deletions

4
nvm Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
source "$(cd $(dirname $0);pwd -P)/nvm.sh"
nvm "$@"
exit $?

38
nvm.sh Executable file → Normal file
View File

@ -4,7 +4,6 @@
#
# Implemented by Tim Caswell <tim@creationix.com>
# with much bash help from Matthew Ranney
# Auto detect the NVM_DIR
if [ ! -d "$NVM_DIR" ]; then
export NVM_DIR=$(cd $(dirname ${BASH_SOURCE[0]:-$0}) && pwd)
@ -37,7 +36,13 @@ nvm_ls()
{
PATTERN=$1
VERSIONS=''
CURRENT_NODE="$(which node)"
if [ "$PATTERN" = 'current' ]; then
if [ "${CURRENT_NODE##$NVM_DIR}" = "${CURRENT_NODE}" ]; then
echo "N/A"
return
fi
echo `node -v 2>/dev/null`
return
fi
@ -89,7 +94,10 @@ nvm()
echo " nvm install <version> Download and install a <version>"
echo " nvm uninstall <version> Uninstall a version"
echo " nvm use <version> Modify PATH to use <version>"
echo " nvm run <version> [<args>] Run <version> with <args> as arguments"
echo " nvm run [<version>] [<args>] Run <version> with <args> as arguments"
echo " nvm which [<version>] Prints the path of the currently used node executable"
echo " nvm root [<version>] Prints the root path of the currently used node version"
echo " nvm bin [<version>] Prints the path to the 'bin' directory of the currently used node version"
echo " nvm ls List installed versions"
echo " nvm ls <version> List versions matching a given description"
echo " nvm deactivate Undo effects of NVM on current shell"
@ -249,6 +257,32 @@ nvm()
echo "Running node $VERSION"
$NVM_DIR/$VERSION/bin/node "${@:3}"
;;
"which" )
# prints out the current node binary
VERSION=`nvm_version $2`
if [ ! -d $NVM_DIR/$VERSION ]; then
echo "$VERSION version is not installed yet"
return;
fi
echo $NVM_DIR/$VERSION/bin/node
;;
"bin" )
# prints out the current node binary
VERSION=`nvm_version $2`
if [ ! -d $NVM_DIR/$VERSION ]; then
echo "$VERSION version is not installed yet"
return;
fi
echo $NVM_DIR/$VERSION/bin
;;
"root" )
VERSION=`nvm_version $2`
if [ ! -d $NVM_DIR/$VERSION ]; then
echo "$VERSION version is not installed yet"
return;
fi
echo $NVM_DIR/$VERSION
;;
"ls" | "list" )
print_versions "`nvm_ls $2`"
if [ $# -eq 1 ]; then