mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00

- Add a (large) speedup by moving some logic to Bash for the typical case of a normal or dev-cmd, Bash or Ruby command. - Make `brew command` a non-developer command, I don't think it makes sense to consider it something needed for developing Homebrew. - Update the manpage/tests/RBI accordingly. Co-authored-by: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>
47 lines
1.2 KiB
Bash
47 lines
1.2 KiB
Bash
# does the quickest output of brew command possible for the basic cases of an
|
|
# official Bash or Ruby normal or dev-cmd command.
|
|
# HOMEBREW_LIBRARY is set by brew.sh
|
|
# shellcheck disable=SC2154
|
|
homebrew-command-path() {
|
|
case "$1" in
|
|
# check we actually have command and not e.g. commandsomething
|
|
command) ;;
|
|
*) return 1 ;;
|
|
esac
|
|
|
|
local first_command found_command
|
|
for arg in "$@"
|
|
do
|
|
if [[ -z "${first_command}" && "${arg}" == "command" ]]
|
|
then
|
|
first_command=1
|
|
continue
|
|
elif [[ -f "${HOMEBREW_LIBRARY}/Homebrew/cmd/${arg}.sh" ]]
|
|
then
|
|
echo "${HOMEBREW_LIBRARY}/Homebrew/cmd/${arg}.sh"
|
|
found_command=1
|
|
elif [[ -f "${HOMEBREW_LIBRARY}/Homebrew/dev-cmd/${arg}.sh" ]]
|
|
then
|
|
echo "${HOMEBREW_LIBRARY}/Homebrew/dev-cmd/${arg}.sh"
|
|
found_command=1
|
|
elif [[ -f "${HOMEBREW_LIBRARY}/Homebrew/cmd/${arg}.rb" ]]
|
|
then
|
|
echo "${HOMEBREW_LIBRARY}/Homebrew/cmd/${arg}.rb"
|
|
found_command=1
|
|
elif [[ -f "${HOMEBREW_LIBRARY}/Homebrew/dev-cmd/${arg}.rb" ]]
|
|
then
|
|
echo "${HOMEBREW_LIBRARY}/Homebrew/dev-cmd/${arg}.rb"
|
|
found_command=1
|
|
else
|
|
return 1
|
|
fi
|
|
done
|
|
|
|
if [[ -n "${found_command}" ]]
|
|
then
|
|
return 0
|
|
else
|
|
return 1
|
|
fi
|
|
}
|