From 04a61fbca454e517fdf3b6ce902a1795fab8c80f Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Fri, 16 Dec 2022 13:37:15 -0800 Subject: [PATCH 1/2] items.sh: return early when no Taps directory --- Library/Homebrew/items.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/items.sh b/Library/Homebrew/items.sh index 4a65589731..4c436fed39 100644 --- a/Library/Homebrew/items.sh +++ b/Library/Homebrew/items.sh @@ -17,6 +17,7 @@ homebrew-items() { # HOMEBREW_REPOSITORY is set by brew.sh # shellcheck disable=SC2154 + [[ -d "${HOMEBREW_REPOSITORY}/Library/Taps" ]] || return items="$( find "${HOMEBREW_REPOSITORY}/Library/Taps" \ -type d \( \ From a0e9352ad2fc0da605db93525d8eaaf4a1337bfb Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Mon, 19 Dec 2022 16:30:49 -0800 Subject: [PATCH 2/2] cmd/formulae.sh: read cached JSON when using API --- Library/Homebrew/cmd/formulae.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/formulae.sh b/Library/Homebrew/cmd/formulae.sh index 649af45c9e..9812e9ce3c 100644 --- a/Library/Homebrew/cmd/formulae.sh +++ b/Library/Homebrew/cmd/formulae.sh @@ -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}" }