Consolidate and avoid sed/cut calls, clean up pattern matches
Some patterns contained a no-op `*`; the `*` would match the empty string because # or % replacement (unlike ## or %%) tries to find the shortest match.master
parent
c34502ebc2
commit
0dc177bf9c
15
nvm.sh
15
nvm.sh
|
@ -307,7 +307,7 @@ nvm_is_valid_version() {
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm_normalize_version() {
|
nvm_normalize_version() {
|
||||||
echo "${1#v*}" | command awk -F. '{ printf("%d%06d%06d\n", $1,$2,$3); }'
|
echo "${1#v}" | command awk -F. '{ printf("%d%06d%06d\n", $1,$2,$3); }'
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm_ensure_version_prefix() {
|
nvm_ensure_version_prefix() {
|
||||||
|
@ -324,7 +324,7 @@ nvm_format_version() {
|
||||||
local VERSION
|
local VERSION
|
||||||
VERSION="$(nvm_ensure_version_prefix "$1")"
|
VERSION="$(nvm_ensure_version_prefix "$1")"
|
||||||
if [ "_$(nvm_num_version_groups "$VERSION")" != "_3" ]; then
|
if [ "_$(nvm_num_version_groups "$VERSION")" != "_3" ]; then
|
||||||
nvm_format_version "${VERSION%*\.}.0"
|
nvm_format_version "${VERSION%.}.0"
|
||||||
else
|
else
|
||||||
echo "$VERSION"
|
echo "$VERSION"
|
||||||
fi
|
fi
|
||||||
|
@ -510,7 +510,7 @@ nvm_strip_iojs_prefix() {
|
||||||
if [ "_$1" = "_$NVM_IOJS_PREFIX" ]; then
|
if [ "_$1" = "_$NVM_IOJS_PREFIX" ]; then
|
||||||
echo
|
echo
|
||||||
else
|
else
|
||||||
echo "${1#"$NVM_IOJS_PREFIX"-*}"
|
echo "${1#"$NVM_IOJS_PREFIX"-}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -565,7 +565,7 @@ nvm_ls() {
|
||||||
local NUM_VERSION_GROUPS
|
local NUM_VERSION_GROUPS
|
||||||
NUM_VERSION_GROUPS="$(nvm_num_version_groups "$PATTERN")"
|
NUM_VERSION_GROUPS="$(nvm_num_version_groups "$PATTERN")"
|
||||||
if [ "_$NUM_VERSION_GROUPS" = "_2" ] || [ "_$NUM_VERSION_GROUPS" = "_1" ]; then
|
if [ "_$NUM_VERSION_GROUPS" = "_2" ] || [ "_$NUM_VERSION_GROUPS" = "_1" ]; then
|
||||||
PATTERN="${PATTERN%*\.}."
|
PATTERN="${PATTERN%.}."
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
@ -681,9 +681,10 @@ nvm_ls_remote_iojs() {
|
||||||
PATTERN=".*"
|
PATTERN=".*"
|
||||||
fi
|
fi
|
||||||
VERSIONS="$(nvm_download -L -s $NVM_IOJS_ORG_VERSION_LISTING -o - \
|
VERSIONS="$(nvm_download -L -s $NVM_IOJS_ORG_VERSION_LISTING -o - \
|
||||||
| command sed 1d \
|
| command sed "
|
||||||
| command sed "s/^/$(nvm_iojs_prefix)-/" \
|
1d;
|
||||||
| command cut -f1 \
|
s/^/$(nvm_iojs_prefix)-/;
|
||||||
|
s/[[:blank:]].*//" \
|
||||||
| command grep -w "$PATTERN" \
|
| command grep -w "$PATTERN" \
|
||||||
| command sort)"
|
| command sort)"
|
||||||
if [ -z "$VERSIONS" ]; then
|
if [ -z "$VERSIONS" ]; then
|
||||||
|
|
Loading…
Reference in New Issue