Skip to content
Myr

Fix nvm ls for v* numbers

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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 there

authored by Koen Punt · committed by Koen Punt · parent 0b97ee1 · Browse files · 1 file+23 added−16 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+23 added−16 removed

  • other:+23 added−16 removed

1 file+23 added−16 removed

modified:nvm.sh+23 added-16 removed
65 unmodified lines
66 return67 fi68}6970nvm_normalize_version() {71 echo "$1" | sed -e 's/^v//' | awk -F. '{ printf("%d%03d%03d\n", $1,$2,$3); }'72}7374nvm_format_version() {75 echo "$1" | sed -e 's/^\([0-9]\)/v\1/g'76}77 78nvm_binary_available() {79 # binaries started with node 0.8.680 local MINIMAL="0.8.6"81 local VERSION=$182 [ $(nvm_normalize_version $VERSION) -ge $(nvm_normalize_version $MINIMAL) ]83}8485nvm_ls() {86 local PATTERN=$187 local VERSIONS=''88 if [ "$PATTERN" = 'current' ]; then
8 unmodified lines
97 # If it looks like an explicit version, don't do anything funny98 if [ `expr "$PATTERN" : "v[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*$"` != 0 ]; then99 VERSIONS="$PATTERN"100 else86 VERSIONS=`find "$NVM_DIR/" -maxdepth 1 -type d -name "v$PATTERN*" -exec basename '{}' ';' \101 VERSIONS=`find "$NVM_DIR/" -maxdepth 1 -type d -name "$(nvm_format_version $PATTERN)*" -exec basename '{}' ';' \102 | sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n`103 fi104 if [ -z "$VERSIONS" ]; then105 echo "N/A"
7 unmodified lines
113 local PATTERN=$1114 local VERSIONS115 local GREP_OPTIONS=''116 if [ -n "$PATTERN" ]; then102 if echo "${PATTERN}" | \grep -v '^v' ; then103 PATTERN=v$PATTERN104 fi117 PATTERN=`nvm_format_version "$PATTERN"`118 else119 PATTERN=".*"120 fi121 VERSIONS=`curl -s $NVM_NODEJS_ORG_MIRROR/ \
152 unmodified lines
274 # skip binary install if no binary option specified.275 if [ $nobinary -ne 1 ]; then276 # shortcut - try the binary if possible.277 if [ -n "$os" ]; then265 binavail=266 # binaries started with node 0.8.6267 case "$VERSION" in268 v0.8.[012345]) binavail=0 ;;269 v0.[1234567].*) binavail=0 ;;270 *) binavail=1 ;;271 esac272 if [ $binavail -eq 1 ]; then278 if nvm_binary_available "$VERSION"; then279 t="$VERSION-$os-$arch"280 url="$NVM_NODEJS_ORG_MIRROR/$VERSION/node-${t}.tar.gz"281 sum=`curl -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt | \grep node-${t}.tar.gz | awk '{print $1}'`282 local tmpdir="$NVM_DIR/bin/node-${t}"
68 unmodified lines
351 fi352 ;;353 "uninstall" )354 [ $# -ne 2 ] && nvm help && return355 PATTERN=`nvm_format_version $2`349 if [ "$2" = `nvm_version` ]; then350 echo "nvm: Cannot uninstall currently-active node version, $2."356 if [[ $PATTERN == `nvm_version` ]]; then357 echo "nvm: Cannot uninstall currently-active node version, $PATTERN."358 return 1359 fi353 VERSION=`nvm_version $2`354 if [ ! -d "$NVM_DIR/$VERSION" ]; then360 VERSION=`nvm_version $PATTERN`361 if [ ! -d $NVM_DIR/$VERSION ]; then362 echo "$VERSION version is not installed..."363 return;364 fi365
193 unmodified lines