brew.sh: alias which
as type -P
This commit is contained in:
parent
f14fcc810e
commit
d77d510ce9
@ -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
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user