From bc9c82cb9fa1dd13607b8d576a11f662980f16c5 Mon Sep 17 00:00:00 2001 From: GPad Date: Tue, 22 Jan 2013 13:28:13 +0100 Subject: [PATCH 1/2] read version from .nvmrc if not specified --- nvm.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/nvm.sh b/nvm.sh index fcf1189..05dccae 100755 --- a/nvm.sh +++ b/nvm.sh @@ -16,6 +16,14 @@ if [ ! -z "$(which unsetopt 2>/dev/null)" ]; then unsetopt nomatch 2>/dev/null fi +# Obtain nvm version from rc file +function rc_nvm_version { + if [ -e .nvmrc ]; then + RC_VERSION=`cat .nvmrc | head -n 1` + echo "Found .nvmrc files with version <$RC_VERSION>" + fi +} + # Expand a version using the version cache nvm_version() { @@ -348,6 +356,18 @@ nvm() nvm help return fi + if [ $# -eq 1 ]; then + rc_nvm_version + if [ ! -z $RC_VERSION ]; then + VERSION=`nvm_version $RC_VERSION` + fi + else + VERSION=`nvm_version $2` + fi + if [ -z $VERSION ]; then + nvm help + return + fi VERSION=`nvm_version $2` if [ ! -d $NVM_DIR/$VERSION ]; then echo "$VERSION version is not installed yet" From 7226e5fb9867545219e8979788a9e28b13c3450a Mon Sep 17 00:00:00 2001 From: GPad Date: Fri, 25 Jan 2013 19:13:40 +0100 Subject: [PATCH 2/2] read the .nvmrc if present --- nvm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nvm.sh b/nvm.sh index 05dccae..10b153a 100755 --- a/nvm.sh +++ b/nvm.sh @@ -352,7 +352,7 @@ nvm() fi ;; "use" ) - if [ $# -ne 2 ]; then + if [ $# -eq 0 ]; then nvm help return fi