commit
1eaf6e2db7
73
nvm.sh
73
nvm.sh
|
@ -20,34 +20,56 @@ fi
|
||||||
nvm_version()
|
nvm_version()
|
||||||
{
|
{
|
||||||
PATTERN=$1
|
PATTERN=$1
|
||||||
VERSION=''
|
# The default version is the current one
|
||||||
|
if [ ! "$PATTERN" ]; then
|
||||||
|
PATTERN='current'
|
||||||
|
fi
|
||||||
|
|
||||||
|
VERSION=`nvm_ls $PATTERN | tail -n1`
|
||||||
|
echo "$VERSION"
|
||||||
|
|
||||||
|
if [ "$VERSION" = 'N/A' ]; then
|
||||||
|
return 13
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
nvm_ls()
|
||||||
|
{
|
||||||
|
PATTERN=$1
|
||||||
|
VERSIONS=''
|
||||||
|
if [ "$PATTERN" = 'current' ]; then
|
||||||
|
VERSION=`node -v 2>/dev/null`
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -f "$NVM_DIR/alias/$PATTERN" ]; then
|
if [ -f "$NVM_DIR/alias/$PATTERN" ]; then
|
||||||
nvm_version `cat $NVM_DIR/alias/$PATTERN`
|
nvm_version `cat $NVM_DIR/alias/$PATTERN`
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
# If it looks like an explicit version, don't do anything funny
|
# If it looks like an explicit version, don't do anything funny
|
||||||
if [[ "$PATTERN" == v?*.?*.?* ]]; then
|
if [[ "$PATTERN" == v?*.?*.?* ]]; then
|
||||||
VERSION="$PATTERN"
|
VERSIONS="$PATTERN"
|
||||||
|
else
|
||||||
|
VERSIONS=`(cd $NVM_DIR; \ls -d v${PATTERN}* 2>/dev/null) | sort -t. -k 1.2,1n -k 2,2n -k 3,3n`
|
||||||
fi
|
fi
|
||||||
# The default version is the current one
|
if [ ! "$VERSIONS" ]; then
|
||||||
if [ ! "$PATTERN" -o "$PATTERN" = 'current' ]; then
|
echo "N/A"
|
||||||
VERSION=`node -v 2>/dev/null`
|
|
||||||
fi
|
|
||||||
if [ "$PATTERN" = 'all' ]; then
|
|
||||||
(cd $NVM_DIR; \ls -dG v* 2>/dev/null || echo "N/A")
|
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
if [ ! "$VERSION" ]; then
|
echo "$VERSIONS"
|
||||||
VERSION=`(cd $NVM_DIR; \ls -d v${PATTERN}* 2>/dev/null) | sort -t. -k 2,1n -k 2,2n -k 3,3n | tail -n1`
|
return
|
||||||
fi
|
}
|
||||||
if [ ! "$VERSION" ]; then
|
|
||||||
echo "N/A"
|
print_versions()
|
||||||
return 13
|
{
|
||||||
elif [ -e "$NVM_DIR/$VERSION" ]; then
|
OUTPUT=''
|
||||||
(cd $NVM_DIR; \ls -dG "$VERSION")
|
for VERSION in $1; do
|
||||||
else
|
PADDED_VERSION=`printf '%10s' $VERSION`
|
||||||
echo "$VERSION"
|
if [[ -d "$NVM_DIR/$VERSION" ]]; then
|
||||||
fi
|
PADDED_VERSION="\033[0;34m$PADDED_VERSION\033[0m"
|
||||||
|
fi
|
||||||
|
OUTPUT="$OUTPUT\n$PADDED_VERSION"
|
||||||
|
done
|
||||||
|
echo -e "$OUTPUT" | column
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm()
|
nvm()
|
||||||
|
@ -214,13 +236,12 @@ nvm()
|
||||||
$NVM_DIR/$VERSION/bin/node "${@:3}"
|
$NVM_DIR/$VERSION/bin/node "${@:3}"
|
||||||
;;
|
;;
|
||||||
"ls" | "list" )
|
"ls" | "list" )
|
||||||
if [ $# -ne 1 ]; then
|
print_versions "`nvm_ls $2`"
|
||||||
nvm_version $2
|
if [ $# -eq 1 ]; then
|
||||||
return
|
echo -ne "current: \t"; nvm_version current
|
||||||
|
nvm alias
|
||||||
fi
|
fi
|
||||||
nvm_version all
|
return
|
||||||
echo -ne "current: \t"; nvm_version current
|
|
||||||
nvm alias
|
|
||||||
;;
|
;;
|
||||||
"alias" )
|
"alias" )
|
||||||
mkdir -p $NVM_DIR/alias
|
mkdir -p $NVM_DIR/alias
|
||||||
|
@ -275,7 +296,7 @@ nvm()
|
||||||
echo "Cache cleared."
|
echo "Cache cleared."
|
||||||
;;
|
;;
|
||||||
"version" )
|
"version" )
|
||||||
nvm_version $2
|
print_versions "`nvm_version $2`"
|
||||||
;;
|
;;
|
||||||
* )
|
* )
|
||||||
nvm help
|
nvm help
|
||||||
|
|
Loading…
Reference in New Issue