Skip to content

Commit 5f62dab

Browse files
committed
[Robustness] handle an overridden type
Fixes nvm-sh#2352
1 parent 0579718 commit 5f62dab

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

nvm.sh

+10-10
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ nvm_grep() {
4545
}
4646

4747
nvm_has() {
48-
type "${1-}" >/dev/null 2>&1
48+
command type "${1-}" >/dev/null 2>&1
4949
}
5050

5151
nvm_has_non_aliased() {
@@ -61,18 +61,18 @@ nvm_command_info() {
6161
local COMMAND
6262
local INFO
6363
COMMAND="${1}"
64-
if type "${COMMAND}" | nvm_grep -q hashed; then
65-
INFO="$(type "${COMMAND}" | command sed -E 's/\(|\)//g' | command awk '{print $4}')"
66-
elif type "${COMMAND}" | nvm_grep -q aliased; then
64+
if command type "${COMMAND}" | nvm_grep -q hashed; then
65+
INFO="$(nvm_has "${COMMAND}" | command sed -E 's/\(|\)//g' | command awk '{print $4}')"
66+
elif command type "${COMMAND}" | nvm_grep -q aliased; then
6767
# shellcheck disable=SC2230
68-
INFO="$(which "${COMMAND}") ($(type "${COMMAND}" | command awk '{ $1=$2=$3=$4="" ;print }' | command sed -e 's/^\ *//g' -Ee "s/\`|'//g"))"
69-
elif type "${COMMAND}" | nvm_grep -q "^${COMMAND} is an alias for"; then
68+
INFO="$(which "${COMMAND}") ($(nvm_has "${COMMAND}" | command awk '{ $1=$2=$3=$4="" ;print }' | command sed -e 's/^\ *//g' -Ee "s/\`|'//g"))"
69+
elif command type "${COMMAND}" | nvm_grep -q "^${COMMAND} is an alias for"; then
7070
# shellcheck disable=SC2230
71-
INFO="$(which "${COMMAND}") ($(type "${COMMAND}" | command awk '{ $1=$2=$3=$4=$5="" ;print }' | command sed 's/^\ *//g'))"
72-
elif type "${COMMAND}" | nvm_grep -q "^${COMMAND} is \\/"; then
73-
INFO="$(type "${COMMAND}" | command awk '{print $3}')"
71+
INFO="$(which "${COMMAND}") ($(nvm_has "${COMMAND}" | command awk '{ $1=$2=$3=$4=$5="" ;print }' | command sed 's/^\ *//g'))"
72+
elif command type "${COMMAND}" | nvm_grep -q "^${COMMAND} is \\/"; then
73+
INFO="$(nvm_has "${COMMAND}" | command awk '{print $3}')"
7474
else
75-
INFO="$(type "${COMMAND}")"
75+
INFO="$(nvm_has "${COMMAND}")"
7676
fi
7777
nvm_echo "${INFO}"
7878
}

0 commit comments

Comments
 (0)