Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

nvm_ls minor versions #466

Merged
merged 3 commits into from

2 participants

Jordan Harband Koen Punt
Jordan Harband
Collaborator

Fixes #401.

nvm.sh
@@ -158,7 +158,11 @@ nvm_ls() {
VERSIONS="$PATTERN"
fi
else
- VERSIONS=`find "$NVM_DIR/" -maxdepth 1 -type d -name "$(nvm_format_version $PATTERN)*" -exec basename '{}' ';' \
+ PATTERN=$(nvm_format_version $PATTERN)
+ if [ `expr "$PATTERN" : "v[[:digit:]]*\.[[:digit:]]]*$"` != 0 ]; then

Strange that this works, there is a ] too many: \.[[:digit:]]]*$"`

And is there a reason we use [[:digit:]] and not [0-9]?

Jordan Harband Collaborator
ljharb added a note

hm - good call. perhaps because of the *?

It's because that's what's used already in the file, 6 lines higher.

I know that it has been used before, but I just tested the [0-9] in the different shells and it doesn't make a difference. So maybe update both to [0-9]?

Jordan Harband Collaborator
ljharb added a note

Updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Jordan Harband ljharb referenced this pull request from a commit
Jordan Harband ljharb Use [0-9] instead of [[:digit:]] per #466 (comment) - it's simpler (a…
…nd probably more portable).
11e3531
Jordan Harband ljharb merged commit 1a9ab82 into from
Jordan Harband ljharb referenced this pull request from a commit in travis-ci/travis-images
Josh Kalderimis joshk remove most node js aliases
these are recognized by default by NVM

<3<3<3 @ljharb
6ec39db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
8 nvm.sh
View
@@ -153,12 +153,16 @@ nvm_ls() {
return
fi
# If it looks like an explicit version, don't do anything funny
- if [ `expr "$PATTERN" : "v[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*$"` != 0 ]; then
+ if [ `expr "$PATTERN" : "v[0-9]*\.[0-9]*\.[0-9]*$"` != 0 ]; then
if [ -d "$NVM_DIR/$PATTERN" ]; then
VERSIONS="$PATTERN"
fi
else
- VERSIONS=`find "$NVM_DIR/" -maxdepth 1 -type d -name "$(nvm_format_version $PATTERN)*" -exec basename '{}' ';' \
+ PATTERN=$(nvm_format_version $PATTERN)
+ if [ `expr "$PATTERN" : "v[0-9]*\.[0-9]*$"` != 0 ]; then
+ PATTERN="$PATTERN."
+ fi
+ VERSIONS=`find "$NVM_DIR/" -maxdepth 1 -type d -name "$PATTERN*" -exec basename '{}' ';' \
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n | \grep -v '^ *\.'`
fi
if [ -z "$VERSIONS" ]; then
37 test/fast/Listing versions/Running "nvm ls 0.2" should display only 0.2.x versions.
View
@@ -2,11 +2,40 @@
mkdir ../../../v0.1.3
mkdir ../../../v0.2.3
+mkdir ../../../v0.20.3
. ../../../nvm.sh
+die () { echo $@ ; exit 1; }
+
# The result should contain only the appropriate version numbers.
-nvm ls 0.2 | grep v0.2.3 &&
-nvm ls 0.1 | grep -v v0.2.3 &&
-nvm ls 0.1 | grep v0.1.3 &&
-nvm ls v0.2 | grep v0.2.3
+
+nvm ls 0.1 | grep 'v0.2.3' > /dev/null
+if [ $? -eq 0 ]; then
+ echo '"nvm ls 0.1" contained v0.2.3'
+fi
+
+nvm ls 0.1 | grep 'v0.20.3' > /dev/null
+if [ $? -eq 0 ]; then
+ die '"nvm ls 0.1" contained v0.20.3'
+fi
+
+nvm ls 0.1 | grep 'v0.1.3' > /dev/null
+if [ $? -ne 0 ]; then
+ die '"nvm ls 0.1" did not contain v0.1.3'
+fi
+
+nvm ls 0.2 | grep 'v0.2.3' > /dev/null
+if [ $? -ne 0 ]; then
+ die '"nvm ls 0.2" did not contain v0.2.3'
+fi
+
+nvm ls 0.2 | grep 'v0.20.3' > /dev/null
+if [ $? -eq 0 ]; then
+ die '"nvm ls 0.2" contained v0.20.3'
+fi
+
+nvm ls 0.2 | grep 'v0.2.3' > /dev/null
+if [ $? -ne 0 ]; then
+ die '"nvm ls 0.2" did not contain v0.2.3'
+fi
Something went wrong with that request. Please try again.