Fixing indentation and adding a trailing newline.

master
Jordan Harband 2014-02-15 15:57:51 -08:00
parent 0d5ee024d1
commit 304cc29cf0
1 changed files with 88 additions and 87 deletions

175
nvm.sh
View File

@ -15,137 +15,137 @@ has() {
# Make zsh glob matching behave same as bash # Make zsh glob matching behave same as bash
# This fixes the "zsh: no matches found" errors # This fixes the "zsh: no matches found" errors
if has "unsetopt"; then if has "unsetopt"; then
unsetopt nomatch 2>/dev/null unsetopt nomatch 2>/dev/null
NVM_CD_FLAGS="-q" NVM_CD_FLAGS="-q"
fi fi
# Auto detect the NVM_DIR # Auto detect the NVM_DIR
if [ ! -d "$NVM_DIR" ]; then if [ ! -d "$NVM_DIR" ]; then
export NVM_DIR=$(cd $NVM_CD_FLAGS $(dirname ${BASH_SOURCE[0]:-$0}) > /dev/null && pwd) export NVM_DIR=$(cd $NVM_CD_FLAGS $(dirname ${BASH_SOURCE[0]:-$0}) > /dev/null && pwd)
fi fi
# Setup mirror location if not already set # Setup mirror location if not already set
if [ -z "$NVM_NODEJS_ORG_MIRROR" ]; then if [ -z "$NVM_NODEJS_ORG_MIRROR" ]; then
export NVM_NODEJS_ORG_MIRROR="http://nodejs.org/dist" export NVM_NODEJS_ORG_MIRROR="http://nodejs.org/dist"
fi fi
nvm_set_nullglob() { nvm_set_nullglob() {
if has "setopt"; then if has "setopt"; then
# Zsh # Zsh
setopt NULL_GLOB setopt NULL_GLOB
else else
# Bash # Bash
shopt -s nullglob shopt -s nullglob
fi fi
} }
# Obtain nvm version from rc file # Obtain nvm version from rc file
rc_nvm_version() { rc_nvm_version() {
if [ -e .nvmrc ]; then if [ -e .nvmrc ]; then
RC_VERSION=`cat .nvmrc | head -n 1` RC_VERSION=`cat .nvmrc | head -n 1`
echo "Found .nvmrc files with version <$RC_VERSION>" echo "Found .nvmrc files with version <$RC_VERSION>"
fi fi
} }
# Expand a version using the version cache # Expand a version using the version cache
nvm_version() { nvm_version() {
local PATTERN=$1 local PATTERN=$1
# The default version is the current one # The default version is the current one
if [ ! "$PATTERN" ]; then if [ ! "$PATTERN" ]; then
PATTERN='current' PATTERN='current'
fi fi
VERSION=`nvm_ls $PATTERN | tail -n1` VERSION=`nvm_ls $PATTERN | tail -n1`
echo "$VERSION" echo "$VERSION"
if [ "$VERSION" = 'N/A' ]; then if [ "$VERSION" = 'N/A' ]; then
return return
fi fi
} }
nvm_remote_version() { nvm_remote_version() {
local PATTERN=$1 local PATTERN=$1
VERSION=`nvm_ls_remote $PATTERN | tail -n1` VERSION=`nvm_ls_remote $PATTERN | tail -n1`
echo "$VERSION" echo "$VERSION"
if [ "$VERSION" = 'N/A' ]; then if [ "$VERSION" = 'N/A' ]; then
return return
fi fi
} }
nvm_ls() { nvm_ls() {
local PATTERN=$1 local PATTERN=$1
local VERSIONS='' local VERSIONS=''
if [ "$PATTERN" = 'current' ]; then if [ "$PATTERN" = 'current' ]; then
echo `node -v 2>/dev/null` echo `node -v 2>/dev/null`
return
fi
if [ -f "$NVM_DIR/alias/$PATTERN" ]; then
nvm_version `cat $NVM_DIR/alias/$PATTERN`
return
fi
# If it looks like an explicit version, don't do anything funny
if [[ "$PATTERN" == v?*.?*.?* ]]; then
VERSIONS="$PATTERN"
else
VERSIONS=`find "$NVM_DIR/" -maxdepth 1 -type d -name "v$PATTERN*" -exec basename '{}' ';' \
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n`
fi
if [ ! "$VERSIONS" ]; then
echo "N/A"
return
fi
echo "$VERSIONS"
return return
fi
if [ -f "$NVM_DIR/alias/$PATTERN" ]; then
nvm_version `cat $NVM_DIR/alias/$PATTERN`
return
fi
# If it looks like an explicit version, don't do anything funny
if [[ "$PATTERN" == v?*.?*.?* ]]; then
VERSIONS="$PATTERN"
else
VERSIONS=`find "$NVM_DIR/" -maxdepth 1 -type d -name "v$PATTERN*" -exec basename '{}' ';' \
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n`
fi
if [ ! "$VERSIONS" ]; then
echo "N/A"
return
fi
echo "$VERSIONS"
return
} }
nvm_ls_remote() { nvm_ls_remote() {
local PATTERN=$1 local PATTERN=$1
local VERSIONS local VERSIONS
if [ "$PATTERN" ]; then if [ "$PATTERN" ]; then
if echo "${PATTERN}" | \grep -v '^v' ; then if echo "${PATTERN}" | \grep -v '^v' ; then
PATTERN=v$PATTERN PATTERN=v$PATTERN
fi
else
PATTERN=".*"
fi fi
VERSIONS=`curl -s $NVM_NODEJS_ORG_MIRROR/ \ else
| \egrep -o 'v[0-9]+\.[0-9]+\.[0-9]+' \ PATTERN=".*"
| \grep -w "${PATTERN}" \ fi
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n` VERSIONS=`curl -s $NVM_NODEJS_ORG_MIRROR/ \
if [ ! "$VERSIONS" ]; then | \egrep -o 'v[0-9]+\.[0-9]+\.[0-9]+' \
echo "N/A" | \grep -w "${PATTERN}" \
return | sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n`
fi if [ ! "$VERSIONS" ]; then
echo "$VERSIONS" echo "N/A"
return return
fi
echo "$VERSIONS"
return
} }
nvm_checksum() { nvm_checksum() {
if [ "$1" = "$2" ]; then if [ "$1" = "$2" ]; then
return return
elif [ -z $2 ]; then elif [ -z $2 ]; then
echo 'Checksums empty' #missing in raspberry pi binary echo 'Checksums empty' #missing in raspberry pi binary
return return
else else
echo 'Checksums do not match.' echo 'Checksums do not match.'
return 1 return 1
fi fi
} }
print_versions() { print_versions() {
local OUTPUT='' local OUTPUT=''
local PADDED_VERSION='' local PADDED_VERSION=''
for VERSION in $1; do for VERSION in $1; do
PADDED_VERSION=`printf '%10s' $VERSION` PADDED_VERSION=`printf '%10s' $VERSION`
if [[ -d "$NVM_DIR/$VERSION" ]]; then if [[ -d "$NVM_DIR/$VERSION" ]]; then
PADDED_VERSION="\033[0;34m$PADDED_VERSION\033[0m" PADDED_VERSION="\033[0;34m$PADDED_VERSION\033[0m"
fi fi
OUTPUT="$OUTPUT\n$PADDED_VERSION" OUTPUT="$OUTPUT\n$PADDED_VERSION"
done done
echo -e "$OUTPUT" echo -e "$OUTPUT"
} }
nvm() { nvm() {
@ -238,9 +238,9 @@ nvm() {
fi fi
if [ "$os" = "freebsd" ]; then if [ "$os" = "freebsd" ]; then
nobinary=1 nobinary=1
fi fi
[ -d "$NVM_DIR/$1" ] && echo "$1 is already installed." && return [ -d "$NVM_DIR/$1" ] && echo "$1 is already installed." && return
VERSION=`nvm_remote_version $1` VERSION=`nvm_remote_version $1`
@ -298,7 +298,7 @@ nvm() {
sum='' sum=''
make='make' make='make'
if [ "$os" = "freebsd" ]; then if [ "$os" = "freebsd" ]; then
make='gmake' make='gmake'
fi fi
local tmpdir="$NVM_DIR/src" local tmpdir="$NVM_DIR/src"
local tmptarball="$tmpdir/node-$VERSION.tar.gz" local tmptarball="$tmpdir/node-$VERSION.tar.gz"
@ -543,3 +543,4 @@ nvm() {
} }
nvm ls default &>/dev/null && nvm use default >/dev/null || true nvm ls default &>/dev/null && nvm use default >/dev/null || true