Skip to content
/ nvm Public
forked from nvm-sh/nvm

Commit 352936e

Browse files
committed
[Robustness] handle an overridden type
Fixes nvm-sh#2352
1 parent ec8906b commit 352936e

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

nvm.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ nvm_grep() {
4646
}
4747

4848
nvm_has() {
49-
type "${1-}" >/dev/null 2>&1
49+
command type "${1-}" >/dev/null 2>&1
5050
}
5151

5252
nvm_has_non_aliased() {
@@ -62,18 +62,18 @@ nvm_command_info() {
6262
local COMMAND
6363
local INFO
6464
COMMAND="${1}"
65-
if type "${COMMAND}" | nvm_grep -q hashed; then
66-
INFO="$(type "${COMMAND}" | command sed -E 's/\(|\)//g' | command awk '{print $4}')"
67-
elif type "${COMMAND}" | nvm_grep -q aliased; then
65+
if command type "${COMMAND}" | nvm_grep -q hashed; then
66+
INFO="$(command type "${COMMAND}" | command sed -E 's/\(|\)//g' | command awk '{print $4}')"
67+
elif command type "${COMMAND}" | nvm_grep -q aliased; then
6868
# shellcheck disable=SC2230
69-
INFO="$(which "${COMMAND}") ($(type "${COMMAND}" | command awk '{ $1=$2=$3=$4="" ;print }' | command sed -e 's/^\ *//g' -Ee "s/\`|'//g"))"
70-
elif type "${COMMAND}" | nvm_grep -q "^${COMMAND} is an alias for"; then
69+
INFO="$(which "${COMMAND}") ($(command type "${COMMAND}" | command awk '{ $1=$2=$3=$4="" ;print }' | command sed -e 's/^\ *//g' -Ee "s/\`|'//g"))"
70+
elif command type "${COMMAND}" | nvm_grep -q "^${COMMAND} is an alias for"; then
7171
# shellcheck disable=SC2230
72-
INFO="$(which "${COMMAND}") ($(type "${COMMAND}" | command awk '{ $1=$2=$3=$4=$5="" ;print }' | command sed 's/^\ *//g'))"
73-
elif type "${COMMAND}" | nvm_grep -q "^${COMMAND} is /"; then
74-
INFO="$(type "${COMMAND}" | command awk '{print $3}')"
72+
INFO="$(which "${COMMAND}") ($(command type "${COMMAND}" | command awk '{ $1=$2=$3=$4=$5="" ;print }' | command sed 's/^\ *//g'))"
73+
elif command type "${COMMAND}" | nvm_grep -q "^${COMMAND} is /"; then
74+
INFO="$(command type "${COMMAND}" | command awk '{print $3}')"
7575
else
76-
INFO="$(type "${COMMAND}")"
76+
INFO="$(command type "${COMMAND}")"
7777
fi
7878
nvm_echo "${INFO}"
7979
}

0 commit comments

Comments
 (0)