Separating variable declaration from first assignment, which should fix some ksh problems.
parent
bb01513eba
commit
4c9a36e9ad
70
nvm.sh
70
nvm.sh
|
@ -46,7 +46,8 @@ nvm_find_up() {
|
||||||
|
|
||||||
|
|
||||||
nvm_find_nvmrc() {
|
nvm_find_nvmrc() {
|
||||||
local dir="$(nvm_find_up '.nvmrc')"
|
local dir
|
||||||
|
dir="$(nvm_find_up '.nvmrc')"
|
||||||
if [ -e "$dir/.nvmrc" ]; then
|
if [ -e "$dir/.nvmrc" ]; then
|
||||||
echo "$dir/.nvmrc"
|
echo "$dir/.nvmrc"
|
||||||
fi
|
fi
|
||||||
|
@ -54,7 +55,8 @@ nvm_find_nvmrc() {
|
||||||
|
|
||||||
# Obtain nvm version from rc file
|
# Obtain nvm version from rc file
|
||||||
nvm_rc_version() {
|
nvm_rc_version() {
|
||||||
local NVMRC_PATH="$(nvm_find_nvmrc)"
|
local NVMRC_PATH
|
||||||
|
NVMRC_PATH="$(nvm_find_nvmrc)"
|
||||||
if [ -e "$NVMRC_PATH" ]; then
|
if [ -e "$NVMRC_PATH" ]; then
|
||||||
NVM_RC_VERSION=`cat "$NVMRC_PATH" | head -n 1`
|
NVM_RC_VERSION=`cat "$NVMRC_PATH" | head -n 1`
|
||||||
echo "Found '$NVMRC_PATH' with version <$NVM_RC_VERSION>"
|
echo "Found '$NVMRC_PATH' with version <$NVM_RC_VERSION>"
|
||||||
|
@ -63,7 +65,8 @@ nvm_rc_version() {
|
||||||
|
|
||||||
# Expand a version using the version cache
|
# Expand a version using the version cache
|
||||||
nvm_version() {
|
nvm_version() {
|
||||||
local PATTERN=$1
|
local PATTERN
|
||||||
|
PATTERN=$1
|
||||||
local VERSION
|
local VERSION
|
||||||
# The default version is the current one
|
# The default version is the current one
|
||||||
if [ -z "$PATTERN" ]; then
|
if [ -z "$PATTERN" ]; then
|
||||||
|
@ -79,7 +82,8 @@ nvm_version() {
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm_remote_version() {
|
nvm_remote_version() {
|
||||||
local PATTERN=$1
|
local PATTERN
|
||||||
|
PATTERN=$1
|
||||||
local VERSION
|
local VERSION
|
||||||
VERSION=`nvm_ls_remote $PATTERN | tail -n1`
|
VERSION=`nvm_ls_remote $PATTERN | tail -n1`
|
||||||
echo "$VERSION"
|
echo "$VERSION"
|
||||||
|
@ -111,14 +115,18 @@ nvm_prepend_path() {
|
||||||
|
|
||||||
nvm_binary_available() {
|
nvm_binary_available() {
|
||||||
# binaries started with node 0.8.6
|
# binaries started with node 0.8.6
|
||||||
local MINIMAL="0.8.6"
|
local MINIMAL
|
||||||
local VERSION=$1
|
MINIMAL="0.8.6"
|
||||||
|
local VERSION
|
||||||
|
VERSION=$1
|
||||||
[ $(nvm_normalize_version $VERSION) -ge $(nvm_normalize_version $MINIMAL) ]
|
[ $(nvm_normalize_version $VERSION) -ge $(nvm_normalize_version $MINIMAL) ]
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm_ls() {
|
nvm_ls() {
|
||||||
local PATTERN=$1
|
local PATTERN
|
||||||
local VERSIONS=''
|
PATTERN=$1
|
||||||
|
local VERSIONS
|
||||||
|
VERSIONS=''
|
||||||
if [ "$PATTERN" = 'current' ]; then
|
if [ "$PATTERN" = 'current' ]; then
|
||||||
echo `node -v 2>/dev/null`
|
echo `node -v 2>/dev/null`
|
||||||
return
|
return
|
||||||
|
@ -146,9 +154,11 @@ nvm_ls() {
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm_ls_remote() {
|
nvm_ls_remote() {
|
||||||
local PATTERN=$1
|
local PATTERN
|
||||||
|
PATTERN=$1
|
||||||
local VERSIONS
|
local VERSIONS
|
||||||
local GREP_OPTIONS=''
|
local GREP_OPTIONS
|
||||||
|
GREP_OPTIONS=''
|
||||||
if [ -n "$PATTERN" ]; then
|
if [ -n "$PATTERN" ]; then
|
||||||
PATTERN=`nvm_format_version "$PATTERN"`
|
PATTERN=`nvm_format_version "$PATTERN"`
|
||||||
else
|
else
|
||||||
|
@ -189,9 +199,10 @@ nvm_checksum() {
|
||||||
nvm_print_versions() {
|
nvm_print_versions() {
|
||||||
local VERSION
|
local VERSION
|
||||||
local FORMAT
|
local FORMAT
|
||||||
local CURRENT=`nvm_version current`
|
local NVM_CURRENT
|
||||||
|
NVM_CURRENT=`nvm_version current`
|
||||||
echo "$1" | while read VERSION; do
|
echo "$1" | while read VERSION; do
|
||||||
if [ "$VERSION" = "$CURRENT" ]; then
|
if [ "$VERSION" = "$NVM_CURRENT" ]; then
|
||||||
FORMAT='\033[0;32m-> %9s\033[0m'
|
FORMAT='\033[0;32m-> %9s\033[0m'
|
||||||
elif [ -d "$NVM_DIR/$VERSION" ]; then
|
elif [ -d "$NVM_DIR/$VERSION" ]; then
|
||||||
FORMAT='\033[0;34m%12s\033[0m'
|
FORMAT='\033[0;34m%12s\033[0m'
|
||||||
|
@ -209,10 +220,13 @@ nvm() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Try to figure out the os and arch for binary fetching
|
# Try to figure out the os and arch for binary fetching
|
||||||
local uname="$(uname -a)"
|
local uname
|
||||||
local os=
|
uname="$(uname -a)"
|
||||||
local arch="$(uname -m)"
|
local os
|
||||||
local GREP_OPTIONS=''
|
local arch
|
||||||
|
arch="$(uname -m)"
|
||||||
|
local GREP_OPTIONS
|
||||||
|
GREP_OPTIONS=''
|
||||||
case "$uname" in
|
case "$uname" in
|
||||||
Linux\ *) os=linux ;;
|
Linux\ *) os=linux ;;
|
||||||
Darwin\ *) os=darwin ;;
|
Darwin\ *) os=darwin ;;
|
||||||
|
@ -272,7 +286,8 @@ nvm() {
|
||||||
local sum
|
local sum
|
||||||
local tarball
|
local tarball
|
||||||
local nobinary
|
local nobinary
|
||||||
local version_not_provided=0
|
local version_not_provided
|
||||||
|
version_not_provided=0
|
||||||
local provided_version
|
local provided_version
|
||||||
|
|
||||||
if ! nvm_has "curl"; then
|
if ! nvm_has "curl"; then
|
||||||
|
@ -340,8 +355,10 @@ nvm() {
|
||||||
t="$VERSION-$os-$arch"
|
t="$VERSION-$os-$arch"
|
||||||
url="$NVM_NODEJS_ORG_MIRROR/$VERSION/node-${t}.tar.gz"
|
url="$NVM_NODEJS_ORG_MIRROR/$VERSION/node-${t}.tar.gz"
|
||||||
sum=`curl -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt | \grep node-${t}.tar.gz | awk '{print $1}'`
|
sum=`curl -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt | \grep node-${t}.tar.gz | awk '{print $1}'`
|
||||||
local tmpdir="$NVM_DIR/bin/node-${t}"
|
local tmpdir
|
||||||
local tmptarball="$tmpdir/node-${t}.tar.gz"
|
tmpdir="$NVM_DIR/bin/node-${t}"
|
||||||
|
local tmptarball
|
||||||
|
tmptarball="$tmpdir/node-${t}.tar.gz"
|
||||||
if (
|
if (
|
||||||
mkdir -p "$tmpdir" && \
|
mkdir -p "$tmpdir" && \
|
||||||
curl -L -C - --progress-bar $url -o "$tmptarball" && \
|
curl -L -C - --progress-bar $url -o "$tmptarball" && \
|
||||||
|
@ -370,8 +387,10 @@ nvm() {
|
||||||
make='gmake'
|
make='gmake'
|
||||||
MAKE_CXX="CXX=c++"
|
MAKE_CXX="CXX=c++"
|
||||||
fi
|
fi
|
||||||
local tmpdir="$NVM_DIR/src"
|
local tmpdir
|
||||||
local tmptarball="$tmpdir/node-$VERSION.tar.gz"
|
tmpdir="$NVM_DIR/src"
|
||||||
|
local tmptarball
|
||||||
|
tmptarball="$tmpdir/node-$VERSION.tar.gz"
|
||||||
if [ "`curl -Is "$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then
|
if [ "`curl -Is "$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then
|
||||||
tarball="$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz"
|
tarball="$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz"
|
||||||
sum=`curl -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt | \grep node-$VERSION.tar.gz | awk '{print $1}'`
|
sum=`curl -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt | \grep node-$VERSION.tar.gz | awk '{print $1}'`
|
||||||
|
@ -511,7 +530,8 @@ nvm() {
|
||||||
;;
|
;;
|
||||||
"run" )
|
"run" )
|
||||||
local provided_version
|
local provided_version
|
||||||
local has_checked_nvmrc=0
|
local has_checked_nvmrc
|
||||||
|
has_checked_nvmrc=0
|
||||||
# run given version of node
|
# run given version of node
|
||||||
shift
|
shift
|
||||||
if [ $# -lt 1 ]; then
|
if [ $# -lt 1 ]; then
|
||||||
|
@ -611,8 +631,10 @@ nvm() {
|
||||||
return 127
|
return 127
|
||||||
fi
|
fi
|
||||||
VERSION=`nvm_version $2`
|
VERSION=`nvm_version $2`
|
||||||
local ROOT=`(nvm use $VERSION && npm -g root)`
|
local ROOT
|
||||||
local ROOTDEPTH=$((`echo $ROOT | sed 's/[^\/]//g'|wc -m` -1))
|
ROOT=`(nvm use $VERSION && npm -g root)`
|
||||||
|
local ROOTDEPTH
|
||||||
|
ROOTDEPTH=$((`echo $ROOT | sed 's/[^\/]//g'|wc -m` -1))
|
||||||
|
|
||||||
# declare local INSTALLS first, otherwise it doesn't work in zsh
|
# declare local INSTALLS first, otherwise it doesn't work in zsh
|
||||||
local INSTALLS
|
local INSTALLS
|
||||||
|
|
Loading…
Reference in New Issue