mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-05-12 07:01:50 +00:00
Use "typeset" instead of "local" for portability
This commit is contained in:
parent
a69eae10e3
commit
c5737228fc
84
nvm.sh
84
nvm.sh
@ -44,8 +44,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
|
typeset PATTERN=$1
|
||||||
local VERSION
|
typeset VERSION
|
||||||
# The default version is the current one
|
# The default version is the current one
|
||||||
if [ -z "$PATTERN" ]; then
|
if [ -z "$PATTERN" ]; then
|
||||||
PATTERN='current'
|
PATTERN='current'
|
||||||
@ -60,8 +60,8 @@ nvm_version() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nvm_remote_version() {
|
nvm_remote_version() {
|
||||||
local PATTERN=$1
|
typeset PATTERN=$1
|
||||||
local VERSION
|
typeset VERSION
|
||||||
VERSION=`nvm_ls_remote $PATTERN | tail -n1`
|
VERSION=`nvm_ls_remote $PATTERN | tail -n1`
|
||||||
echo "$VERSION"
|
echo "$VERSION"
|
||||||
|
|
||||||
@ -80,14 +80,14 @@ nvm_format_version() {
|
|||||||
|
|
||||||
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"
|
typeset MINIMAL="0.8.6"
|
||||||
local VERSION=$1
|
typeset 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
|
typeset PATTERN=$1
|
||||||
local VERSIONS=''
|
typeset VERSIONS=''
|
||||||
if [ "$PATTERN" = 'current' ]; then
|
if [ "$PATTERN" = 'current' ]; then
|
||||||
echo `node -v 2>/dev/null`
|
echo `node -v 2>/dev/null`
|
||||||
return
|
return
|
||||||
@ -113,9 +113,9 @@ nvm_ls() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nvm_ls_remote() {
|
nvm_ls_remote() {
|
||||||
local PATTERN=$1
|
typeset PATTERN=$1
|
||||||
local VERSIONS
|
typeset VERSIONS
|
||||||
local GREP_OPTIONS=''
|
typeset GREP_OPTIONS=''
|
||||||
if [ -n "$PATTERN" ]; then
|
if [ -n "$PATTERN" ]; then
|
||||||
PATTERN=`nvm_format_version "$PATTERN"`
|
PATTERN=`nvm_format_version "$PATTERN"`
|
||||||
else
|
else
|
||||||
@ -154,9 +154,9 @@ nvm_checksum() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nvm_print_versions() {
|
nvm_print_versions() {
|
||||||
local VERSION
|
typeset VERSION
|
||||||
local FORMAT
|
typeset FORMAT
|
||||||
local CURRENT=`nvm_version current`
|
typeset CURRENT=`nvm_version current`
|
||||||
echo "$1" | while read VERSION; do
|
echo "$1" | while read VERSION; do
|
||||||
if [ "$VERSION" = "$CURRENT" ]; then
|
if [ "$VERSION" = "$CURRENT" ]; then
|
||||||
FORMAT='\033[0;32m-> %9s\033[0m'
|
FORMAT='\033[0;32m-> %9s\033[0m'
|
||||||
@ -176,10 +176,10 @@ 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)"
|
typeset uname="$(uname -a)"
|
||||||
local os=
|
typeset os=
|
||||||
local arch="$(uname -m)"
|
typeset arch="$(uname -m)"
|
||||||
local GREP_OPTIONS=''
|
typeset GREP_OPTIONS=''
|
||||||
case "$uname" in
|
case "$uname" in
|
||||||
Linux\ *) os=linux ;;
|
Linux\ *) os=linux ;;
|
||||||
Darwin\ *) os=darwin ;;
|
Darwin\ *) os=darwin ;;
|
||||||
@ -192,10 +192,10 @@ nvm() {
|
|||||||
*armv6l*) arch=arm-pi ;;
|
*armv6l*) arch=arm-pi ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# initialize local variables
|
# initialize typeset variables
|
||||||
local VERSION
|
typeset VERSION
|
||||||
local ADDITIONAL_PARAMETERS
|
typeset ADDITIONAL_PARAMETERS
|
||||||
local ALIAS
|
typeset ALIAS
|
||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
"help" )
|
"help" )
|
||||||
@ -231,15 +231,15 @@ nvm() {
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
"install" )
|
"install" )
|
||||||
# initialize local variables
|
# initialize typeset variables
|
||||||
local binavail
|
typeset binavail
|
||||||
local t
|
typeset t
|
||||||
local url
|
typeset url
|
||||||
local sum
|
typeset sum
|
||||||
local tarball
|
typeset tarball
|
||||||
local nobinary
|
typeset nobinary
|
||||||
local version_not_provided=0
|
typeset version_not_provided=0
|
||||||
local provided_version
|
typeset provided_version
|
||||||
|
|
||||||
if ! nvm_has "curl"; then
|
if ! nvm_has "curl"; then
|
||||||
echo 'NVM Needs curl to proceed.' >&2;
|
echo 'NVM Needs curl to proceed.' >&2;
|
||||||
@ -297,8 +297,8 @@ 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}"
|
typeset tmpdir="$NVM_DIR/bin/node-${t}"
|
||||||
local tmptarball="$tmpdir/node-${t}.tar.gz"
|
typeset 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" && \
|
||||||
@ -327,8 +327,8 @@ nvm() {
|
|||||||
make='gmake'
|
make='gmake'
|
||||||
MAKE_CXX="CXX=c++"
|
MAKE_CXX="CXX=c++"
|
||||||
fi
|
fi
|
||||||
local tmpdir="$NVM_DIR/src"
|
typeset tmpdir="$NVM_DIR/src"
|
||||||
local tmptarball="$tmpdir/node-$VERSION.tar.gz"
|
typeset 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}'`
|
||||||
@ -471,8 +471,8 @@ nvm() {
|
|||||||
echo "Now using node $VERSION"
|
echo "Now using node $VERSION"
|
||||||
;;
|
;;
|
||||||
"run" )
|
"run" )
|
||||||
local provided_version
|
typeset provided_version
|
||||||
local has_checked_nvmrc=0
|
typeset has_checked_nvmrc=0
|
||||||
# run given version of node
|
# run given version of node
|
||||||
shift
|
shift
|
||||||
if [ $# -lt 1 ]; then
|
if [ $# -lt 1 ]; then
|
||||||
@ -531,7 +531,7 @@ nvm() {
|
|||||||
"alias" )
|
"alias" )
|
||||||
mkdir -p $NVM_DIR/alias
|
mkdir -p $NVM_DIR/alias
|
||||||
if [ $# -le 2 ]; then
|
if [ $# -le 2 ]; then
|
||||||
local DEST
|
typeset DEST
|
||||||
for ALIAS in $NVM_DIR/alias/$2*; do
|
for ALIAS in $NVM_DIR/alias/$2*; do
|
||||||
if [ -e "$ALIAS" ]; then
|
if [ -e "$ALIAS" ]; then
|
||||||
DEST=`cat $ALIAS`
|
DEST=`cat $ALIAS`
|
||||||
@ -575,11 +575,11 @@ nvm() {
|
|||||||
return 127
|
return 127
|
||||||
fi
|
fi
|
||||||
VERSION=`nvm_version $2`
|
VERSION=`nvm_version $2`
|
||||||
local ROOT=`(nvm use $VERSION && npm -g root)`
|
typeset ROOT=`(nvm use $VERSION && npm -g root)`
|
||||||
local ROOTDEPTH=$((`echo $ROOT | sed 's/[^\/]//g'|wc -m` -1))
|
typeset ROOTDEPTH=$((`echo $ROOT | sed 's/[^\/]//g'|wc -m` -1))
|
||||||
|
|
||||||
# declare local INSTALLS first, otherwise it doesn't work in zsh
|
# declare typeset INSTALLS first, otherwise it doesn't work in zsh
|
||||||
local INSTALLS
|
typeset INSTALLS
|
||||||
INSTALLS=`nvm use $VERSION > /dev/null && npm -g -p ll | \grep "$ROOT\/[^/]\+$" | cut -d '/' -f $(($ROOTDEPTH + 2)) | cut -d ":" -f 2 | \grep -v npm | tr "\n" " "`
|
INSTALLS=`nvm use $VERSION > /dev/null && npm -g -p ll | \grep "$ROOT\/[^/]\+$" | cut -d '/' -f $(($ROOTDEPTH + 2)) | cut -d ":" -f 2 | \grep -v npm | tr "\n" " "`
|
||||||
|
|
||||||
npm install -g ${INSTALLS[@]}
|
npm install -g ${INSTALLS[@]}
|
||||||
|
Loading…
Reference in New Issue
Block a user