[Fix] nvm_strip_path: avoid gawk-specific RT variable for mawk compatibility

This commit is contained in:
Jordan Harband
2026-01-26 22:33:58 -08:00
parent 92e0ec2ac2
commit faa8585c6f

11
nvm.sh
View File

@@ -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() {