@@ -775,34 +775,40 @@ nvm_ls() {
775
775
fi
776
776
fi
777
777
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
779
779
NVM_DIRS_TO_SEARCH1=' '
780
780
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
782
782
NVM_DIRS_TO_SEARCH2=" $NVM_DIRS_TO_SEARCH1 "
783
783
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
785
785
NVM_DIRS_TO_SEARCH3=" $NVM_DIRS_TO_SEARCH2 "
786
786
fi
787
787
788
+ local SEARCH_PATTERN
788
789
if [ -z " $PATTERN " ]; then
789
790
PATTERN=' v'
791
+ SEARCH_PATTERN=' .*'
792
+ else
793
+ SEARCH_PATTERN=" $( echo " ${PATTERN} " | sed " s#\.#\\ \.#g;" ) "
790
794
fi
791
795
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 *" \
793
797
| 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 ;
797
801
\#^versions\$ # d;
798
802
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
+ " \
806
812
) "
807
813
fi
808
814
0 commit comments