Skip to content
Myr

Consolidate and avoid sed/cut calls, clean up pattern matches

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Some patterns contained a no-op `*`; the `*` would match the empty string because # or % replacement (unlike ## or %%) tries to find the shortest match.

authored by Jo Liss · committed by Jo Liss · parent c34502e · Browse files · 1 file+8 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+8 added−7 removed

  • other:+8 added−7 removed

1 file+8 added−7 removed

modified:nvm.sh+8 added-7 removed
305 unmodified lines
306 esac307}308309nvm_normalize_version() {310 echo "${1#v*}" | command awk -F. '{ printf("%d%06d%06d\n", $1,$2,$3); }'310 echo "${1#v}" | command awk -F. '{ printf("%d%06d%06d\n", $1,$2,$3); }'311}312313nvm_ensure_version_prefix() {314 local NVM_VERSION
8 unmodified lines
323nvm_format_version() {324 local VERSION325 VERSION="$(nvm_ensure_version_prefix "$1")"326 if [ "_$(nvm_num_version_groups "$VERSION")" != "_3" ]; then327 nvm_format_version "${VERSION%*\.}.0"327 nvm_format_version "${VERSION%.}.0"328 else329 echo "$VERSION"330 fi331}
177 unmodified lines
509 NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"510 if [ "_$1" = "_$NVM_IOJS_PREFIX" ]; then511 echo512 else513 echo "${1#"$NVM_IOJS_PREFIX"-*}"513 echo "${1#"$NVM_IOJS_PREFIX"-}"514 fi515}516517nvm_ls() {
46 unmodified lines
564 *)565 local NUM_VERSION_GROUPS566 NUM_VERSION_GROUPS="$(nvm_num_version_groups "$PATTERN")"567 if [ "_$NUM_VERSION_GROUPS" = "_2" ] || [ "_$NUM_VERSION_GROUPS" = "_1" ]; then568 PATTERN="${PATTERN%*\.}."568 PATTERN="${PATTERN%.}."569 fi570 ;;571 esac572
107 unmodified lines
680 else681 PATTERN=".*"682 fi683 VERSIONS="$(nvm_download -L -s $NVM_IOJS_ORG_VERSION_LISTING -o - \684 | command sed 1d \685 | command sed "s/^/$(nvm_iojs_prefix)-/" \686 | command cut -f1 \684 | command sed "685 1d;686 s/^/$(nvm_iojs_prefix)-/;687 s/[[:blank:]].*//" \688 | command grep -w "$PATTERN" \689 | command sort)"690 if [ -z "$VERSIONS" ]; then691 echo "N/A"
1070 unmodified lines