Make `nvm ls` support listing the "versions" directory when it's present.

master
Jordan Harband 2014-08-20 00:42:50 -07:00
parent 65c2435418
commit 5dd2d7e5d4
3 changed files with 20 additions and 2 deletions

7
nvm.sh
View File

@ -229,8 +229,13 @@ nvm_ls() {
if [ `expr "$PATTERN" : "v[0-9]*\.[0-9]*$"` != 0 ]; then if [ `expr "$PATTERN" : "v[0-9]*\.[0-9]*$"` != 0 ]; then
PATTERN="$PATTERN." PATTERN="$PATTERN."
fi fi
VERSIONS=`find "$NVM_DIR/" -maxdepth 1 -type d -name "$PATTERN*" -exec basename '{}' ';' \ if [ -d "$(nvm_version_dir new)" ]; then
VERSIONS=`find "$(nvm_version_dir new)/" "$(nvm_version_dir old)/" -maxdepth 1 -type d -name "$PATTERN*" -exec basename '{}' ';' \
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n | \grep -v '^ *\.' | \grep -e '^v'` | sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n | \grep -v '^ *\.' | \grep -e '^v'`
else
VERSIONS=`find "$(nvm_version_dir old)/" -maxdepth 1 -type d -name "$PATTERN*" -exec basename '{}' ';' \
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n | \grep -v '^ *\.' | \grep -e '^v'`
fi
fi fi
if [ -z "$VERSIONS" ]; then if [ -z "$VERSIONS" ]; then
echo "N/A" echo "N/A"

View File

@ -0,0 +1,12 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
mkdir -p ../../../versions/v0.12.1
mkdir ../../../v0.1.3
. ../../../nvm.sh
nvm ls 0.12 | grep v0.12.1 || die '"nvm ls" did not list a version in the versions/ directory'
nvm ls 0.1 | grep v0.1.3 || die '"nvm ls" did not list a version not in the versions/ directory'

View File

@ -7,5 +7,6 @@ rmdir ../../../v0.2.3
rmdir ../../../v0.3.1 rmdir ../../../v0.3.1
rmdir ../../../v0.3.3 rmdir ../../../v0.3.3
rmdir ../../../v0.3.9 rmdir ../../../v0.3.9
rmdir ../../../versions
unalias nvm_has_system_node unalias nvm_has_system_node