Merge pull request #12060 from XuehaiPan/alias-which-as-type
brew.sh: alias `which` as `type -P`
This commit is contained in:
commit
1e83399e31
@ -137,6 +137,12 @@ git() {
|
|||||||
"${HOMEBREW_LIBRARY}/Homebrew/shims/scm/git" "$@"
|
"${HOMEBREW_LIBRARY}/Homebrew/shims/scm/git" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Search given executable in PATH (remove dependency for `which` command)
|
||||||
|
which() {
|
||||||
|
# Alias to Bash built-in command `type -P`
|
||||||
|
type -P "$@"
|
||||||
|
}
|
||||||
|
|
||||||
numeric() {
|
numeric() {
|
||||||
# Condense the exploded argument into a single return value.
|
# Condense the exploded argument into a single return value.
|
||||||
# shellcheck disable=SC2086,SC2183
|
# shellcheck disable=SC2086,SC2183
|
||||||
|
|||||||
@ -1,27 +1,5 @@
|
|||||||
export HOMEBREW_REQUIRED_RUBY_VERSION=2.6.3
|
export HOMEBREW_REQUIRED_RUBY_VERSION=2.6.3
|
||||||
|
|
||||||
# Search given executable in all PATH entries (remove dependency for `which` command)
|
|
||||||
which_all() {
|
|
||||||
if [[ $# -ne 1 ]]
|
|
||||||
then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
local executable entries entry retcode=1
|
|
||||||
IFS=':' read -r -a entries <<< "${PATH}" # `readarray -d ':' -t` seems not applicable on WSL Bash
|
|
||||||
for entry in "${entries[@]}"
|
|
||||||
do
|
|
||||||
executable="${entry}/$1"
|
|
||||||
if [[ -x "${executable}" ]]
|
|
||||||
then
|
|
||||||
echo "${executable}"
|
|
||||||
retcode=0 # present
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
return "${retcode}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# HOMEBREW_LIBRARY is from the user environment
|
# HOMEBREW_LIBRARY is from the user environment
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
test_ruby() {
|
test_ruby() {
|
||||||
@ -46,13 +24,18 @@ find_ruby() {
|
|||||||
local ruby_exec
|
local ruby_exec
|
||||||
while read -r ruby_exec
|
while read -r ruby_exec
|
||||||
do
|
do
|
||||||
if test_ruby "${ruby_exec}"; then
|
if test_ruby "${ruby_exec}"
|
||||||
|
then
|
||||||
echo "${ruby_exec}"
|
echo "${ruby_exec}"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done < <(
|
done < <(
|
||||||
which_all ruby
|
# function which() is set by brew.sh
|
||||||
PATH="${HOMEBREW_PATH}" which_all ruby
|
# it's aliased to `type -P`
|
||||||
|
# shellcheck disable=SC2230
|
||||||
|
which -a ruby
|
||||||
|
# shellcheck disable=SC2230
|
||||||
|
PATH="${HOMEBREW_PATH}" which -a ruby
|
||||||
)
|
)
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
6
bin/brew
6
bin/brew
@ -7,6 +7,12 @@ if ! [[ -d "${PWD}" ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Fail fast with concise message when not using bash
|
||||||
|
if [ -z "${BASH_VERSION:-}" ]; then
|
||||||
|
echo "Error: Bash is required to run brew." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
quiet_cd() {
|
quiet_cd() {
|
||||||
cd "$@" &>/dev/null || return
|
cd "$@" &>/dev/null || return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,7 @@ it does it too. You have to confirm everything it will do before it starts.
|
|||||||
* Command Line Tools (CLT) for Xcode: `xcode-select --install`,
|
* Command Line Tools (CLT) for Xcode: `xcode-select --install`,
|
||||||
[developer.apple.com/downloads](https://developer.apple.com/downloads) or
|
[developer.apple.com/downloads](https://developer.apple.com/downloads) or
|
||||||
[Xcode](https://itunes.apple.com/us/app/xcode/id497799835) <sup>[3](#3)</sup>
|
[Xcode](https://itunes.apple.com/us/app/xcode/id497799835) <sup>[3](#3)</sup>
|
||||||
* A Bourne-compatible shell for installation (e.g. `bash` or `zsh`) <sup>[4](#4)</sup>
|
* The Bourne-again shell for installation (i.e. `bash`) <sup>[4](#4)</sup>
|
||||||
|
|
||||||
## Git Remote Mirroring
|
## Git Remote Mirroring
|
||||||
|
|
||||||
@ -75,5 +75,5 @@ Apple Developer account on older versions of Mac OS X. Sign up for free
|
|||||||
[here](https://developer.apple.com/register/index.action).
|
[here](https://developer.apple.com/register/index.action).
|
||||||
|
|
||||||
<a name="4"><sup>4</sup></a> The one-liner installation method found on
|
<a name="4"><sup>4</sup></a> The one-liner installation method found on
|
||||||
[brew.sh](https://brew.sh) requires a Bourne-compatible shell (e.g. bash or
|
[brew.sh](https://brew.sh) requires the Bourne-again shell, i.e. bash.
|
||||||
zsh). Notably, fish, tcsh and csh will not work.
|
Notably, zsh, fish, tcsh and csh will not work.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user