Skip to content

Commit b0244a1

Browse files
committed
[Fix] nvm ls: avoid use of maxdepth which is not on Solaris/SmartOS
Fixes #1121.
1 parent fdc0812 commit b0244a1

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

nvm.sh

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -775,34 +775,40 @@ nvm_ls() {
775775
fi
776776
fi
777777

778-
if ! [ -d "$NVM_DIRS_TO_SEARCH1" ]; then
778+
if ! [ -d "$NVM_DIRS_TO_SEARCH1" ] || ! (command ls -1qA "$NVM_DIRS_TO_SEARCH1" | command grep -q .); then
779779
NVM_DIRS_TO_SEARCH1=''
780780
fi
781-
if ! [ -d "$NVM_DIRS_TO_SEARCH2" ]; then
781+
if ! [ -d "$NVM_DIRS_TO_SEARCH2" ] || ! (command ls -1qA "$NVM_DIRS_TO_SEARCH2" | command grep -q .); then
782782
NVM_DIRS_TO_SEARCH2="$NVM_DIRS_TO_SEARCH1"
783783
fi
784-
if ! [ -d "$NVM_DIRS_TO_SEARCH3" ]; then
784+
if ! [ -d "$NVM_DIRS_TO_SEARCH3" ] || ! (command ls -1qA "$NVM_DIRS_TO_SEARCH3" | command grep -q .); then
785785
NVM_DIRS_TO_SEARCH3="$NVM_DIRS_TO_SEARCH2"
786786
fi
787787

788+
local SEARCH_PATTERN
788789
if [ -z "$PATTERN" ]; then
789790
PATTERN='v'
791+
SEARCH_PATTERN='.*'
792+
else
793+
SEARCH_PATTERN="$(echo "${PATTERN}" | sed "s#\.#\\\.#g;")"
790794
fi
791795
if [ -n "$NVM_DIRS_TO_SEARCH1$NVM_DIRS_TO_SEARCH2$NVM_DIRS_TO_SEARCH3" ]; then
792-
VERSIONS="$(command find "$NVM_DIRS_TO_SEARCH1" "$NVM_DIRS_TO_SEARCH2" "$NVM_DIRS_TO_SEARCH3" -maxdepth 1 -type d -name "$PATTERN*" \
796+
VERSIONS="$(command find "$NVM_DIRS_TO_SEARCH1"/* "$NVM_DIRS_TO_SEARCH2"/* "$NVM_DIRS_TO_SEARCH3"/* -name . -o -type d -prune -o -name "$PATTERN*" \
793797
| command sed "
794-
s#$NVM_VERSION_DIR_IOJS/#$NVM_IOJS_PREFIX-#;
795-
\#$NVM_VERSION_DIR_IOJS# d;
796-
s#^$NVM_DIR/##;
798+
s#${NVM_VERSION_DIR_IOJS}/#versions/${NVM_IOJS_PREFIX}/#;
799+
s#^${NVM_DIR}/##;
800+
\#^[^v]# d;
797801
\#^versions\$# d;
798802
s#^versions/##;
799-
s#^v#$NVM_NODE_PREFIX-v#;
800-
s#^\($NVM_IOJS_PREFIX\)[-/]v#\1.v#;
801-
s#^\($NVM_NODE_PREFIX\)[-/]v#\1.v#" \
802-
| command sort -t. -u -k 2.2,2n -k 3,3n -k 4,4n \
803-
| command sed "
804-
s/^\($NVM_IOJS_PREFIX\)\./\1-/;
805-
s/^$NVM_NODE_PREFIX\.//" \
803+
s#^v#${NVM_NODE_PREFIX}/v#;
804+
\#${SEARCH_PATTERN}# !d;
805+
" \
806+
| command sed -E "s#^([^/]+)/(.*)\$#\2.\1#;" \
807+
| command sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n \
808+
| command sed -E "
809+
s#(.*)\.([^\.]+)\$#\2-\1#;
810+
s#^${NVM_NODE_PREFIX}-##;
811+
" \
806812
)"
807813
fi
808814

0 commit comments

Comments
 (0)