diff --git a/nvm.sh b/nvm.sh index 54a0d376..6af2eb1f 100755 --- a/nvm.sh +++ b/nvm.sh @@ -3292,28 +3292,41 @@ nvm_print_implicit_alias() { LAST_TWO=$($NVM_COMMAND | nvm_grep -e '^v' | command cut -c2- | command cut -d . -f 1,2 | uniq) ;; esac - local MINOR local STABLE STABLE='' local UNSTABLE UNSTABLE='' - local MOD - local NORMALIZED_VERSION - - nvm_is_zsh && setopt local_options shwordsplit - for MINOR in $LAST_TWO; do - NORMALIZED_VERSION="$(nvm_normalize_version "$MINOR")" - if [ "_0${NORMALIZED_VERSION#?}" != "_$NORMALIZED_VERSION" ]; then - STABLE="$MINOR" + local NVM_CLASSIFIED + NVM_CLASSIFIED='' + if [ -n "${LAST_TWO}" ]; then + NVM_CLASSIFIED=$(command awk -v requested="$2" ' + NF { + split($0, parts, /\./); + normalized = sprintf("%d%06d%06d", parts[1], parts[2], parts[3]); + if (substr(normalized, 1, 1) != "0") { + stable = $0; + } else { + parity = int(normalized / 1000000) % 2; + if (parity == 0) { stable = $0; } + else if (parity == 1) { unstable = $0; } + } + } + END { + selected = requested == "stable" ? stable : unstable; + if (selected != "") { print "v" selected; } + } + ' <> "${COUNT_DIR}/calls"' 'exec "${REAL_AWK}" "$@"' > "${COUNT_DIR}/awk" +chmod +x "${COUNT_DIR}/awk" +VERSIONS='v1.0.1 +v1.1.1 +v1.2.1 +v1.3.1 +v1.4.1 +v1.5.1' +RESULT=$(PATH="${COUNT_DIR}:${PATH}" nvm_print_implicit_alias local stable) +[ "${RESULT}" = '1.5' ] || die 'latest minor classification' +CALLS=$(wc -l < "${COUNT_DIR}/calls") +[ "${CALLS}" -le 1 ] || die "classification launched ${CALLS} awk processes for six minors" + +VERSIONS='' +: > "${COUNT_DIR}/calls" +RESULT=$(PATH="${COUNT_DIR}:${PATH}" nvm_print_implicit_alias local unstable) +[ "${RESULT}" = 'N/A' ] || die 'empty unstable classification' +CALLS=$(wc -l < "${COUNT_DIR}/calls") +[ "${CALLS}" -eq 0 ] || die "empty classification launched ${CALLS} awk processes"