Make `nvm_ls foo` work with `iojs`-prefixed version strings.

master
Jordan Harband 2015-01-12 18:16:11 -08:00
parent d28703f9e0
commit f661617f1c
2 changed files with 24 additions and 9 deletions

15
nvm.sh
View File

@ -416,7 +416,12 @@ nvm_ls() {
local NVM_DIRS_TO_TEST_AND_SEARCH local NVM_DIRS_TO_TEST_AND_SEARCH
local NVM_DIRS_TO_SEARCH local NVM_DIRS_TO_SEARCH
NVM_DIRS_TO_TEST_AND_SEARCH="$(nvm_version_dir old) $(nvm_version_dir new)" if nvm_is_iojs_version "$PATTERN"; then
NVM_DIRS_TO_TEST_AND_SEARCH="$(nvm_version_dir iojs)"
PATTERN="$(nvm_strip_iojs_prefix "$PATTERN")"
else
NVM_DIRS_TO_TEST_AND_SEARCH="$(nvm_version_dir old) $(nvm_version_dir new) $(nvm_version_dir iojs)"
fi
for NVM_VERSION_DIR in $NVM_DIRS_TO_TEST_AND_SEARCH; do for NVM_VERSION_DIR in $NVM_DIRS_TO_TEST_AND_SEARCH; do
if [ -d "$NVM_VERSION_DIR" ]; then if [ -d "$NVM_VERSION_DIR" ]; then
NVM_DIRS_TO_SEARCH="$NVM_VERSION_DIR $NVM_DIRS_TO_SEARCH" NVM_DIRS_TO_SEARCH="$NVM_VERSION_DIR $NVM_DIRS_TO_SEARCH"
@ -427,12 +432,16 @@ nvm_ls() {
PATTERN='v' PATTERN='v'
fi fi
VERSIONS="$(command find $NVM_DIRS_TO_SEARCH -maxdepth 1 -type d -name "$PATTERN*" \ VERSIONS="$(command find $NVM_DIRS_TO_SEARCH -maxdepth 1 -type d -name "$PATTERN*" \
| command sed "s#$(nvm_version_dir iojs)/#"$(nvm_iojs_prefix)"-#" \
| command sed "s#^$NVM_DIR/##" \ | command sed "s#^$NVM_DIR/##" \
| command grep -v -e '^versions$' \ | command grep -v -e '^versions$' \
| command sed 's#^versions/##' \
| sed -e 's/^v/node-v/' \ | sed -e 's/^v/node-v/' \
| command sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n \ | sed -e 's#^\(iojs\)[-/]v#\1.v#' | sed -e 's#^\(node\)[-/]v#\1.v#' \
| command sort -t. -u -k 2.2,2n -k 3,3n -k 4,4n \
| command sort -s -t- -k1.1,1.1 \ | command sort -s -t- -k1.1,1.1 \
| command sed 's/^node-//')" | command sed 's/^\(iojs\)\./\1-/' \
| command sed 's/^node\.//')"
if [ $ZHS_HAS_SHWORDSPLIT_UNSET -eq 1 ] && nvm_has "unsetopt"; then if [ $ZHS_HAS_SHWORDSPLIT_UNSET -eq 1 ] && nvm_has "unsetopt"; then
unsetopt shwordsplit unsetopt shwordsplit

View File

@ -8,11 +8,17 @@ mkdir ../../../v0.0.9
mkdir ../../../v0.3.1 mkdir ../../../v0.3.1
mkdir ../../../v0.3.3 mkdir ../../../v0.3.3
mkdir ../../../v0.3.9 mkdir ../../../v0.3.9
mkdir -p ../../../versions/node/v0.12.87
mkdir -p ../../../versions/node/v0.12.9
mkdir -p ../../../versions/io.js/v0.1.2
mkdir -p ../../../versions/io.js/v0.10.2
# The result should contain the version numbers. # The result should contain the version numbers.
nvm ls | grep v0.0.1 && nvm ls | grep v0.0.1 >/dev/null &&
nvm ls | grep v0.0.3 && nvm ls | grep v0.0.3 >/dev/null &&
nvm ls | grep v0.0.9 && nvm ls | grep v0.0.9 >/dev/null &&
nvm ls | grep v0.3.1 && nvm ls | grep v0.3.1 >/dev/null &&
nvm ls | grep v0.3.3 && nvm ls | grep v0.3.3 >/dev/null &&
nvm ls | grep v0.3.9 nvm ls | grep v0.3.9 >/dev/null &&
nvm ls | grep v0.12.87 >/dev/null &&
nvm ls | grep iojs-v0.1.2 >/dev/null