cmd/formulae.sh: read cached JSON when using API

This commit is contained in:
Michael Cho 2022-12-19 16:30:49 -08:00
parent 04a61fbca4
commit a0e9352ad2
No known key found for this signature in database
GPG Key ID: F0487049DAE15338

View File

@ -8,5 +8,17 @@
source "${HOMEBREW_LIBRARY}/Homebrew/items.sh"
homebrew-formulae() {
homebrew-items '*\.rb' 'Casks' 's|/Formula/|/|' '^homebrew/core'
local formulae
formulae="$(homebrew-items '*\.rb' 'Casks' 's|/Formula/|/|' '^homebrew/core')"
# HOMEBREW_CACHE is set by brew.sh
# shellcheck disable=SC2154
if [[ -n "${HOMEBREW_INSTALL_FROM_API}" && -f "${HOMEBREW_CACHE}/api/formula.json" ]]
then
local api_formulae
api_formulae="$(ruby -e "require 'json'; JSON.parse(File.read('${HOMEBREW_CACHE}/api/formula.json')).each { |f| puts f['name'] }" 2>/dev/null)"
formulae="$(echo -e "${formulae}\n${api_formulae}" | sort -uf | grep .)"
fi
echo "${formulae}"
}