Fix nvm ls for v* numbers
Previously calling nvm ls with v* number (nvm ls v0.2) would not return any results. So now the v is prepended if its not already theremaster
parent
0b97ee1d2a
commit
a34c080d77
39
nvm.sh
39
nvm.sh
|
@ -67,6 +67,21 @@ nvm_remote_version() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nvm_normalize_version() {
|
||||||
|
echo "$1" | sed -e 's/^v//' | awk -F. '{ printf("%d%03d%03d\n", $1,$2,$3); }'
|
||||||
|
}
|
||||||
|
|
||||||
|
nvm_format_version() {
|
||||||
|
echo "$1" | sed -e 's/^\([0-9]\)/v\1/g'
|
||||||
|
}
|
||||||
|
|
||||||
|
nvm_binary_available() {
|
||||||
|
# binaries started with node 0.8.6
|
||||||
|
local MINIMAL="0.8.6"
|
||||||
|
local VERSION=$1
|
||||||
|
[ $(nvm_normalize_version $VERSION) -ge $(nvm_normalize_version $MINIMAL) ]
|
||||||
|
}
|
||||||
|
|
||||||
nvm_ls() {
|
nvm_ls() {
|
||||||
local PATTERN=$1
|
local PATTERN=$1
|
||||||
local VERSIONS=''
|
local VERSIONS=''
|
||||||
|
@ -83,7 +98,7 @@ nvm_ls() {
|
||||||
if [ `expr "$PATTERN" : "v[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*$"` != 0 ]; then
|
if [ `expr "$PATTERN" : "v[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*$"` != 0 ]; then
|
||||||
VERSIONS="$PATTERN"
|
VERSIONS="$PATTERN"
|
||||||
else
|
else
|
||||||
VERSIONS=`find "$NVM_DIR/" -maxdepth 1 -type d -name "v$PATTERN*" -exec basename '{}' ';' \
|
VERSIONS=`find "$NVM_DIR/" -maxdepth 1 -type d -name "$(nvm_format_version $PATTERN)*" -exec basename '{}' ';' \
|
||||||
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n`
|
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n`
|
||||||
fi
|
fi
|
||||||
if [ -z "$VERSIONS" ]; then
|
if [ -z "$VERSIONS" ]; then
|
||||||
|
@ -99,9 +114,7 @@ nvm_ls_remote() {
|
||||||
local VERSIONS
|
local VERSIONS
|
||||||
local GREP_OPTIONS=''
|
local GREP_OPTIONS=''
|
||||||
if [ -n "$PATTERN" ]; then
|
if [ -n "$PATTERN" ]; then
|
||||||
if echo "${PATTERN}" | \grep -v '^v' ; then
|
PATTERN=`nvm_format_version "$PATTERN"`
|
||||||
PATTERN=v$PATTERN
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
PATTERN=".*"
|
PATTERN=".*"
|
||||||
fi
|
fi
|
||||||
|
@ -262,14 +275,7 @@ nvm() {
|
||||||
if [ $nobinary -ne 1 ]; then
|
if [ $nobinary -ne 1 ]; then
|
||||||
# shortcut - try the binary if possible.
|
# shortcut - try the binary if possible.
|
||||||
if [ -n "$os" ]; then
|
if [ -n "$os" ]; then
|
||||||
binavail=
|
if nvm_binary_available "$VERSION"; then
|
||||||
# binaries started with node 0.8.6
|
|
||||||
case "$VERSION" in
|
|
||||||
v0.8.[012345]) binavail=0 ;;
|
|
||||||
v0.[1234567].*) binavail=0 ;;
|
|
||||||
*) binavail=1 ;;
|
|
||||||
esac
|
|
||||||
if [ $binavail -eq 1 ]; then
|
|
||||||
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}'`
|
||||||
|
@ -346,12 +352,13 @@ nvm() {
|
||||||
;;
|
;;
|
||||||
"uninstall" )
|
"uninstall" )
|
||||||
[ $# -ne 2 ] && nvm help && return
|
[ $# -ne 2 ] && nvm help && return
|
||||||
if [ "$2" = `nvm_version` ]; then
|
PATTERN=`nvm_format_version $2`
|
||||||
echo "nvm: Cannot uninstall currently-active node version, $2."
|
if [[ $PATTERN == `nvm_version` ]]; then
|
||||||
|
echo "nvm: Cannot uninstall currently-active node version, $PATTERN."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
VERSION=`nvm_version $2`
|
VERSION=`nvm_version $PATTERN`
|
||||||
if [ ! -d "$NVM_DIR/$VERSION" ]; then
|
if [ ! -d $NVM_DIR/$VERSION ]; then
|
||||||
echo "$VERSION version is not installed..."
|
echo "$VERSION version is not installed..."
|
||||||
return;
|
return;
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue