Declare more variables as local

master
Dr. Kibitz 2014-02-16 01:05:24 -08:00
parent 13781f242b
commit 2e9558cbf9
1 changed files with 8 additions and 2 deletions

10
nvm.sh
View File

@ -50,6 +50,7 @@ rc_nvm_version() {
# Expand a version using the version cache # Expand a version using the version cache
nvm_version() { nvm_version() {
local PATTERN=$1 local PATTERN=$1
local VERSION
# The default version is the current one # The default version is the current one
if [ ! "$PATTERN" ]; then if [ ! "$PATTERN" ]; then
PATTERN='current' PATTERN='current'
@ -65,6 +66,7 @@ nvm_version() {
nvm_remote_version() { nvm_remote_version() {
local PATTERN=$1 local PATTERN=$1
local VERSION
VERSION=`nvm_ls_remote $PATTERN | tail -n1` VERSION=`nvm_ls_remote $PATTERN | tail -n1`
echo "$VERSION" echo "$VERSION"
@ -140,8 +142,10 @@ colorize_version() {
} }
print_versions() { print_versions() {
local VERSION
local PADDED_VERSION
for VERSION in $1; do for VERSION in $1; do
local PADDED_VERSION=`printf '%10s' $VERSION` PADDED_VERSION=`printf '%10s' $VERSION`
if [[ -d "$NVM_DIR/$VERSION" ]]; then if [[ -d "$NVM_DIR/$VERSION" ]]; then
colorize_version "$PADDED_VERSION" colorize_version "$PADDED_VERSION"
fi fi
@ -173,6 +177,7 @@ nvm() {
# initialize local variables # initialize local variables
local VERSION local VERSION
local ADDITIONAL_PARAMETERS local ADDITIONAL_PARAMETERS
local ALIAS
case $1 in case $1 in
"help" ) "help" )
@ -479,6 +484,7 @@ nvm() {
"alias" ) "alias" )
mkdir -p $NVM_DIR/alias mkdir -p $NVM_DIR/alias
if [ $# -le 2 ]; then if [ $# -le 2 ]; then
local DEST
for ALIAS in $(nvm_set_nullglob; echo $NVM_DIR/alias/$2* ); do for ALIAS in $(nvm_set_nullglob; echo $NVM_DIR/alias/$2* ); do
DEST=`cat $ALIAS` DEST=`cat $ALIAS`
VERSION=`nvm_version $DEST` VERSION=`nvm_version $DEST`
@ -519,7 +525,7 @@ nvm() {
nvm help nvm help
return return
fi fi
local VERSION=`nvm_version $2` VERSION=`nvm_version $2`
local ROOT=`(nvm use $VERSION && npm -g root)` local ROOT=`(nvm use $VERSION && npm -g root)`
local ROOTDEPTH=$((`echo $ROOT | sed 's/[^\/]//g'|wc -m` -1)) local ROOTDEPTH=$((`echo $ROOT | sed 's/[^\/]//g'|wc -m` -1))