Skip to content

Instantly share code, notes, and snippets.

@Trucido
Last active June 4, 2022 00:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Trucido/6315513d3cb1ac0a30826550761540d2 to your computer and use it in GitHub Desktop.
Save Trucido/6315513d3cb1ac0a30826550761540d2 to your computer and use it in GitHub Desktop.
which2() {
[ -t 1 ] && {
case "${BASH##*/}${ZSH_NAME}" in
(bash) {
{ [ "`builtin type -t $1 2>/dev/null`" = "builtin" ] >&/dev/null; } && \
{ printf '%s is a shell builtin\n' "$1"; return; }
}
{
{ (alias;typeset -f) | \which --tty-only --read-alias --read-functions --show-tilde "$@" >&/dev/null; } && \
{ (alias;typeset -f) | \which --tty-only --read-alias --read-functions --show-tilde "$@" && return $?; }
}
{
{ builtin type -a "$@" >&/dev/null; } && \
{ builtin type -a "$@" && return $?; }
} ;;
(zsh) {
{ [ "`builtin whence -w $1`" = "$1: builtin" ] >&/dev/null; } && \
{ printf '%s is a shell builtin\n' "$1"; return; }
}
{
{ builtin which "$@" >&/dev/null; } && \
{ builtin which "$@" && return $?; }
}
{
{ builtin type -a "$@" >&/dev/null; } && \
{ builtin type -a "$@" && return $?; }
} ;;
esac; }
command -p which "$@"; return $? || return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment