mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Merge pull request #14622 from Bo98/prefix.sh-api
prefix.sh: support API mode
This commit is contained in:
commit
724e3e646a
@ -25,17 +25,33 @@ homebrew-prefix() {
|
|||||||
[[ -z "${prefix}" ]] && return 1
|
[[ -z "${prefix}" ]] && return 1
|
||||||
[[ -z "${formula}" ]] && echo "${HOMEBREW_PREFIX}" && return 0
|
[[ -z "${formula}" ]] && echo "${HOMEBREW_PREFIX}" && return 0
|
||||||
|
|
||||||
local formula_path
|
local formula_exists
|
||||||
if [[ -f "${HOMEBREW_REPOSITORY}/Library/Taps/homebrew/homebrew-core/Formula/${formula}.rb" ]]
|
if [[ -f "${HOMEBREW_REPOSITORY}/Library/Taps/homebrew/homebrew-core/Formula/${formula}.rb" ]]
|
||||||
then
|
then
|
||||||
formula_path="${HOMEBREW_REPOSITORY}/Library/Taps/homebrew/homebrew-core/Formula/${formula}.rb"
|
formula_exists="1"
|
||||||
else
|
else
|
||||||
|
local formula_path
|
||||||
formula_path="$(
|
formula_path="$(
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
echo "${HOMEBREW_REPOSITORY}/Library/Taps"/*/*/{Formula/,HomebrewFormula/,}"${formula}.rb"
|
echo "${HOMEBREW_REPOSITORY}/Library/Taps"/*/*/{Formula/,HomebrewFormula/,}"${formula}.rb"
|
||||||
)"
|
)"
|
||||||
|
[[ -n "${formula_path}" ]] && formula_exists="1"
|
||||||
fi
|
fi
|
||||||
[[ -z "${formula_path}" ]] && return 1
|
|
||||||
|
if [[ -z "${formula_exists}" &&
|
||||||
|
-z "${HOMEBREW_NO_INSTALL_FROM_API}" &&
|
||||||
|
-f "${HOMEBREW_CACHE}/api/formula.json" ]]
|
||||||
|
then
|
||||||
|
formula_exists="$(
|
||||||
|
ruby -rjson <<RUBY 2>/dev/null
|
||||||
|
puts 1 if JSON.parse(File.read("${HOMEBREW_CACHE}/api/formula.json")).any? do |f|
|
||||||
|
f["name"] == "${formula}"
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
[[ -z "${formula_exists}" ]] && return 1
|
||||||
|
|
||||||
echo "${HOMEBREW_PREFIX}/opt/${formula}"
|
echo "${HOMEBREW_PREFIX}/opt/${formula}"
|
||||||
return 0
|
return 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user