[Robustness] handle an overridden type

Fixes #2352
This commit is contained in:
Jordan Harband 2020-11-21 13:33:12 -08:00
parent b19d8dbbba
commit c8d70e07b7
No known key found for this signature in database
GPG Key ID: 9F6A681E35EF8B56

20
nvm.sh
View File

@ -45,7 +45,7 @@ nvm_grep() {
}
nvm_has() {
type "${1-}" >/dev/null 2>&1
command type "${1-}" >/dev/null 2>&1
}
nvm_has_non_aliased() {
@ -61,18 +61,18 @@ nvm_command_info() {
local COMMAND
local INFO
COMMAND="${1}"
if type "${COMMAND}" | nvm_grep -q hashed; then
INFO="$(type "${COMMAND}" | command sed -E 's/\(|\)//g' | command awk '{print $4}')"
elif type "${COMMAND}" | nvm_grep -q aliased; then
if command type "${COMMAND}" | nvm_grep -q hashed; then
INFO="$(command type "${COMMAND}" | command sed -E 's/\(|\)//g' | command awk '{print $4}')"
elif command type "${COMMAND}" | nvm_grep -q aliased; then
# shellcheck disable=SC2230
INFO="$(which "${COMMAND}") ($(type "${COMMAND}" | command awk '{ $1=$2=$3=$4="" ;print }' | command sed -e 's/^\ *//g' -Ee "s/\`|'//g"))"
elif type "${COMMAND}" | nvm_grep -q "^${COMMAND} is an alias for"; then
INFO="$(which "${COMMAND}") ($(command type "${COMMAND}" | command awk '{ $1=$2=$3=$4="" ;print }' | command sed -e 's/^\ *//g' -Ee "s/\`|'//g"))"
elif command type "${COMMAND}" | nvm_grep -q "^${COMMAND} is an alias for"; then
# shellcheck disable=SC2230
INFO="$(which "${COMMAND}") ($(type "${COMMAND}" | command awk '{ $1=$2=$3=$4=$5="" ;print }' | command sed 's/^\ *//g'))"
elif type "${COMMAND}" | nvm_grep -q "^${COMMAND} is \\/"; then
INFO="$(type "${COMMAND}" | command awk '{print $3}')"
INFO="$(which "${COMMAND}") ($(command type "${COMMAND}" | command awk '{ $1=$2=$3=$4=$5="" ;print }' | command sed 's/^\ *//g'))"
elif command type "${COMMAND}" | nvm_grep -q "^${COMMAND} is \\/"; then
INFO="$(command type "${COMMAND}" | command awk '{print $3}')"
else
INFO="$(type "${COMMAND}")"
INFO="$(command type "${COMMAND}")"
fi
nvm_echo "${INFO}"
}