Permalink
Browse files

read version from .nvmrc if not specified

  • Loading branch information...
1 parent f605581 commit bc9c82cb9fa1dd13607b8d576a11f662980f16c5 @gpad gpad committed Jan 22, 2013
Showing with 20 additions and 0 deletions.
  1. +20 −0 nvm.sh
View
20 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 {
@cliffano

cliffano Jun 19, 2013

Contributor

@gpad @creationix Is the use of 'function' here intentional?
I'm using nvm via Jenkins which uses /bin/sh by default, and it complains with "function not found" with this change.
The workaround I use is to change Jenkins to use /bin/bash as the shell of choice.

nvm used to work with /bin/sh, is it now a requirement to use a shell that supports 'function' keyword?

@ljharb

ljharb Jun 19, 2013

Collaborator

Good call. The script should probably have a #!/bin/sh directive at the top, and this function should be an sh function, not a bash function. can you open an issue or a PR about it?

+ 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"

0 comments on commit bc9c82c

Please sign in to comment.