mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-02-05 01:12:52 +08:00
[Fix] nvm_strip_path: avoid gawk-specific RT variable for mawk compatibility
This commit is contained in:
11
nvm.sh
11
nvm.sh
@@ -978,13 +978,18 @@ nvm_strip_path() {
|
|||||||
nvm_err '${NVM_DIR} not set!'
|
nvm_err '${NVM_DIR} not set!'
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
command printf %s "${1-}" | command awk -v NVM_DIR="${NVM_DIR}" -v RS=: '
|
local RESULT
|
||||||
|
RESULT="$(command printf %s "${1-}" | command awk -v NVM_DIR="${NVM_DIR}" -v RS=: '
|
||||||
index($0, NVM_DIR) == 1 {
|
index($0, NVM_DIR) == 1 {
|
||||||
path = substr($0, length(NVM_DIR) + 1)
|
path = substr($0, length(NVM_DIR) + 1)
|
||||||
if (path ~ "^(/versions/[^/]*)?/[^/]*'"${2-}"'.*$") { next }
|
if (path ~ "^(/versions/[^/]*)?/[^/]*'"${2-}"'.*$") { next }
|
||||||
}
|
}
|
||||||
# The final RT will contain a colon if the input has a trailing colon, or a null string otherwise
|
{ printf "%s%s", sep, $0; sep=RS }')"
|
||||||
{ printf "%s%s", sep, $0; sep=RS } END { printf "%s", RT }'
|
# mawk does not support RT, so preserve trailing colon manually
|
||||||
|
case "${1-}" in
|
||||||
|
*:) command printf '%s:' "${RESULT}" ;;
|
||||||
|
*) command printf '%s' "${RESULT}" ;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm_change_path() {
|
nvm_change_path() {
|
||||||
|
|||||||
Reference in New Issue
Block a user