[Fix] `nvm ls`: avoid use of `maxdepth` which is not on Solaris/SmartOS

Fixes #1121.
Jordan Harband 2016-06-24 01:38:27 -07:00
parent fdc08122e3
commit b0244a133b
No known key found for this signature in database
GPG Key ID: 64A196AEE0916D55
1 changed files with 20 additions and 14 deletions

34
nvm.sh
View File

@ -775,34 +775,40 @@ nvm_ls() {
fi fi
fi fi
if ! [ -d "$NVM_DIRS_TO_SEARCH1" ]; then if ! [ -d "$NVM_DIRS_TO_SEARCH1" ] || ! (command ls -1qA "$NVM_DIRS_TO_SEARCH1" | command grep -q .); then
NVM_DIRS_TO_SEARCH1='' NVM_DIRS_TO_SEARCH1=''
fi fi
if ! [ -d "$NVM_DIRS_TO_SEARCH2" ]; then if ! [ -d "$NVM_DIRS_TO_SEARCH2" ] || ! (command ls -1qA "$NVM_DIRS_TO_SEARCH2" | command grep -q .); then
NVM_DIRS_TO_SEARCH2="$NVM_DIRS_TO_SEARCH1" NVM_DIRS_TO_SEARCH2="$NVM_DIRS_TO_SEARCH1"
fi fi
if ! [ -d "$NVM_DIRS_TO_SEARCH3" ]; then if ! [ -d "$NVM_DIRS_TO_SEARCH3" ] || ! (command ls -1qA "$NVM_DIRS_TO_SEARCH3" | command grep -q .); then
NVM_DIRS_TO_SEARCH3="$NVM_DIRS_TO_SEARCH2" NVM_DIRS_TO_SEARCH3="$NVM_DIRS_TO_SEARCH2"
fi fi
local SEARCH_PATTERN
if [ -z "$PATTERN" ]; then if [ -z "$PATTERN" ]; then
PATTERN='v' PATTERN='v'
SEARCH_PATTERN='.*'
else
SEARCH_PATTERN="$(echo "${PATTERN}" | sed "s#\.#\\\.#g;")"
fi fi
if [ -n "$NVM_DIRS_TO_SEARCH1$NVM_DIRS_TO_SEARCH2$NVM_DIRS_TO_SEARCH3" ]; then if [ -n "$NVM_DIRS_TO_SEARCH1$NVM_DIRS_TO_SEARCH2$NVM_DIRS_TO_SEARCH3" ]; then
VERSIONS="$(command find "$NVM_DIRS_TO_SEARCH1" "$NVM_DIRS_TO_SEARCH2" "$NVM_DIRS_TO_SEARCH3" -maxdepth 1 -type d -name "$PATTERN*" \ VERSIONS="$(command find "$NVM_DIRS_TO_SEARCH1"/* "$NVM_DIRS_TO_SEARCH2"/* "$NVM_DIRS_TO_SEARCH3"/* -name . -o -type d -prune -o -name "$PATTERN*" \
| command sed " | command sed "
s#$NVM_VERSION_DIR_IOJS/#$NVM_IOJS_PREFIX-#; s#${NVM_VERSION_DIR_IOJS}/#versions/${NVM_IOJS_PREFIX}/#;
\#$NVM_VERSION_DIR_IOJS# d; s#^${NVM_DIR}/##;
s#^$NVM_DIR/##; \#^[^v]# d;
\#^versions\$# d; \#^versions\$# d;
s#^versions/##; s#^versions/##;
s#^v#$NVM_NODE_PREFIX-v#; s#^v#${NVM_NODE_PREFIX}/v#;
s#^\($NVM_IOJS_PREFIX\)[-/]v#\1.v#; \#${SEARCH_PATTERN}# !d;
s#^\($NVM_NODE_PREFIX\)[-/]v#\1.v#" \ " \
| command sort -t. -u -k 2.2,2n -k 3,3n -k 4,4n \ | command sed -E "s#^([^/]+)/(.*)\$#\2.\1#;" \
| command sed " | command sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n \
s/^\($NVM_IOJS_PREFIX\)\./\1-/; | command sed -E "
s/^$NVM_NODE_PREFIX\.//" \ s#(.*)\.([^\.]+)\$#\2-\1#;
s#^${NVM_NODE_PREFIX}-##;
" \
)" )"
fi fi