Fix `nvm_ls` when `$NVM_DIR` has spaces in it.

Mostly fixes #861.
Jordan Harband 2015-10-07 13:57:29 -07:00
parent 8541e2e1ee
commit 6b3c34313c
1 changed files with 24 additions and 12 deletions

36
nvm.sh
View File

@ -592,39 +592,51 @@ nvm_ls() {
setopt shwordsplit setopt shwordsplit
fi fi
local NVM_DIRS_TO_TEST_AND_SEARCH local NVM_DIRS_TO_SEARCH1
local NVM_DIRS_TO_SEARCH NVM_DIRS_TO_SEARCH1=''
local NVM_DIRS_TO_SEARCH2
NVM_DIRS_TO_SEARCH2=''
local NVM_DIRS_TO_SEARCH3
NVM_DIRS_TO_SEARCH3=''
local NVM_ADD_SYSTEM local NVM_ADD_SYSTEM
NVM_ADD_SYSTEM=false NVM_ADD_SYSTEM=false
if nvm_is_iojs_version "$PATTERN"; then if nvm_is_iojs_version "$PATTERN"; then
NVM_DIRS_TO_TEST_AND_SEARCH="$NVM_VERSION_DIR_IOJS" NVM_DIRS_TO_SEARCH1="$NVM_VERSION_DIR_IOJS"
PATTERN="$(nvm_strip_iojs_prefix "$PATTERN")" PATTERN="$(nvm_strip_iojs_prefix "$PATTERN")"
if nvm_has_system_iojs; then if nvm_has_system_iojs; then
NVM_ADD_SYSTEM=true NVM_ADD_SYSTEM=true
fi fi
elif [ "_$PATTERN" = "_$NVM_NODE_PREFIX-" ]; then elif [ "_$PATTERN" = "_$NVM_NODE_PREFIX-" ]; then
NVM_DIRS_TO_TEST_AND_SEARCH="$NVM_VERSION_DIR_OLD $NVM_VERSION_DIR_NEW" NVM_DIRS_TO_SEARCH1="$NVM_VERSION_DIR_OLD"
NVM_DIRS_TO_SEARCH2="$NVM_VERSION_DIR_NEW"
PATTERN='' PATTERN=''
if nvm_has_system_node; then if nvm_has_system_node; then
NVM_ADD_SYSTEM=true NVM_ADD_SYSTEM=true
fi fi
else else
NVM_DIRS_TO_TEST_AND_SEARCH="$NVM_VERSION_DIR_OLD $NVM_VERSION_DIR_NEW $NVM_VERSION_DIR_IOJS" NVM_DIRS_TO_SEARCH1="$NVM_VERSION_DIR_OLD"
NVM_DIRS_TO_SEARCH2="$NVM_VERSION_DIR_NEW"
NVM_DIRS_TO_SEARCH3="$NVM_VERSION_DIR_IOJS"
if nvm_has_system_iojs || nvm_has_system_node; then if nvm_has_system_iojs || nvm_has_system_node; then
NVM_ADD_SYSTEM=true NVM_ADD_SYSTEM=true
fi fi
fi fi
for NVM_VERSION_DIR in $NVM_DIRS_TO_TEST_AND_SEARCH; do
if [ -d "$NVM_VERSION_DIR" ]; then if ! [ -d "$NVM_DIRS_TO_SEARCH1" ]; then
NVM_DIRS_TO_SEARCH="$NVM_VERSION_DIR $NVM_DIRS_TO_SEARCH" NVM_DIRS_TO_SEARCH1=''
fi fi
done if ! [ -d "$NVM_DIRS_TO_SEARCH2" ]; then
NVM_DIRS_TO_SEARCH2="$NVM_DIRS_TO_SEARCH1"
fi
if ! [ -d "$NVM_DIRS_TO_SEARCH3" ]; then
NVM_DIRS_TO_SEARCH3="$NVM_DIRS_TO_SEARCH2"
fi
if [ -z "$PATTERN" ]; then if [ -z "$PATTERN" ]; then
PATTERN='v' PATTERN='v'
fi fi
if [ -n "$NVM_DIRS_TO_SEARCH" ]; then if [ -n "$NVM_DIRS_TO_SEARCH1$NVM_DIRS_TO_SEARCH2$NVM_DIRS_TO_SEARCH3" ]; then
VERSIONS="$(command find $NVM_DIRS_TO_SEARCH -maxdepth 1 -type d -name "$PATTERN*" \ VERSIONS="$(command find "$NVM_DIRS_TO_SEARCH1" "$NVM_DIRS_TO_SEARCH2" "$NVM_DIRS_TO_SEARCH3" -maxdepth 1 -type d -name "$PATTERN*" \
| command sed " | command sed "
s#$NVM_VERSION_DIR_IOJS/#$NVM_IOJS_PREFIX-#; s#$NVM_VERSION_DIR_IOJS/#$NVM_IOJS_PREFIX-#;
\#$NVM_VERSION_DIR_IOJS# d; \#$NVM_VERSION_DIR_IOJS# d;