Remove external calls to `sed` using parameter filtering.
POSIX-compliant per http://stackoverflow.com/a/25536935/632724 Relates to #709master
parent
d50a0f46e9
commit
d72b35b7b8
15
nvm.sh
15
nvm.sh
|
@ -307,7 +307,7 @@ nvm_is_valid_version() {
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm_normalize_version() {
|
nvm_normalize_version() {
|
||||||
echo "$1" | command sed -e 's/^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,8 +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
|
||||||
VERSION="$(echo "$VERSION" | command sed -e 's/\.*$/.0/')"
|
nvm_format_version "${VERSION%*\.}.0"
|
||||||
nvm_format_version "$VERSION"
|
|
||||||
else
|
else
|
||||||
echo "$VERSION"
|
echo "$VERSION"
|
||||||
fi
|
fi
|
||||||
|
@ -338,10 +337,12 @@ nvm_num_version_groups() {
|
||||||
echo "0"
|
echo "0"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
VERSION="${VERSION#v*}"
|
||||||
|
VERSION="${VERSION%\.}"
|
||||||
local NVM_NUM_DOTS
|
local NVM_NUM_DOTS
|
||||||
NVM_NUM_DOTS=$(echo "$VERSION" | command sed -e 's/^v//' | command sed -e 's/\.$//' | command sed -e 's/[^\.]//g')
|
NVM_NUM_DOTS=$(echo "$VERSION" | command sed -e 's/[^\.]//g')
|
||||||
local NVM_NUM_GROUPS
|
local NVM_NUM_GROUPS
|
||||||
NVM_NUM_GROUPS=".$NVM_NUM_DOTS"
|
NVM_NUM_GROUPS=".$NVM_NUM_DOTS" # add extra dot, since it's (n - 1) dots at this point
|
||||||
echo "${#NVM_NUM_GROUPS}"
|
echo "${#NVM_NUM_GROUPS}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -509,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" | command sed "s/^$NVM_IOJS_PREFIX-//"
|
echo "${1#"$NVM_IOJS_PREFIX"-*}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -564,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="$(echo "$PATTERN" | command sed -e 's/\.*$//g')."
|
PATTERN="${PATTERN%*\.}."
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Reference in New Issue