Skip to content

Commit

Permalink
Merge pull request #170 from tisba/master
Browse files Browse the repository at this point in the history
Avoid pollution of environment
  • Loading branch information
creationix committed Nov 20, 2012
2 parents 1709fa9 + 0803e31 commit 59c8eda
Showing 1 changed file with 38 additions and 24 deletions.
62 changes: 38 additions & 24 deletions nvm.sh
Expand Up @@ -16,24 +16,10 @@ if [ ! -z "$(which unsetopt 2>/dev/null)" ]; then
unsetopt nomatch 2>/dev/null
fi

# Try to figure out the os and arch for binary fetching
uname="$(uname -a)"
os=
arch="$(uname -m)"
case "$uname" in
Linux\ *) os=linux ;;
Darwin\ *) os=darwin ;;
SunOS\ *) os=sunos ;;
esac
case "$uname" in
*x86_64*) arch=x64 ;;
*i*86*) arch=x86 ;;
esac

# Expand a version using the version cache
nvm_version()
{
PATTERN=$1
local PATTERN=$1
# The default version is the current one
if [ ! "$PATTERN" ]; then
PATTERN='current'
Expand All @@ -49,7 +35,7 @@ nvm_version()

nvm_remote_version()
{
PATTERN=$1
local PATTERN=$1
VERSION=`nvm_ls_remote $PATTERN | tail -n1`
echo "$VERSION"

Expand All @@ -60,8 +46,8 @@ nvm_remote_version()

nvm_ls()
{
PATTERN=$1
VERSIONS=''
local PATTERN=$1
local VERSIONS=''
if [ "$PATTERN" = 'current' ]; then
echo `node -v 2>/dev/null`
return
Expand All @@ -87,18 +73,18 @@ nvm_ls()

nvm_ls_remote()
{
PATTERN=$1
local PATTERN=$1
if [ "$PATTERN" ]; then
if echo "${PATTERN}" | grep -v '^v' ; then
PATTERN=v$PATTERN
fi
else
PATTERN=".*"
fi
VERSIONS=`curl -s http://nodejs.org/dist/ \
| egrep -o 'v[0-9]+\.[0-9]+\.[0-9]+' \
| grep -w "${PATTERN}" \
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n`
local VERSIONS=`curl -s http://nodejs.org/dist/ \
| egrep -o 'v[0-9]+\.[0-9]+\.[0-9]+' \
| grep -w "${PATTERN}" \
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n`
if [ ! "$VERSIONS" ]; then
echo "N/A"
return
Expand All @@ -120,7 +106,8 @@ nvm_checksum()

print_versions()
{
OUTPUT=''
local OUTPUT=''
local PADDED_VERSION=''
for VERSION in $1; do
PADDED_VERSION=`printf '%10s' $VERSION`
if [[ -d "$NVM_DIR/$VERSION" ]]; then
Expand All @@ -137,6 +124,25 @@ nvm()
nvm help
return
fi

# Try to figure out the os and arch for binary fetching
local uname="$(uname -a)"
local os=
local arch="$(uname -m)"
case "$uname" in
Linux\ *) os=linux ;;
Darwin\ *) os=darwin ;;
SunOS\ *) os=sunos ;;
esac
case "$uname" in
*x86_64*) arch=x64 ;;
*i*86*) arch=x86 ;;
esac

# initialize local variables
local VERSION
local ADDITIONAL_PARAMETERS

case $1 in
"help" )
echo
Expand Down Expand Up @@ -164,7 +170,15 @@ nvm()
echo " nvm alias default 0.4 Auto use the latest installed v0.4.x version"
echo
;;

"install" )
# initialize local variables
local binavail
local t
local url
local sum
local tarball

if [ ! `which curl` ]; then
echo 'NVM Needs curl to proceed.' >&2;
fi
Expand Down

0 comments on commit 59c8eda

Please sign in to comment.