fix _brew completion default cache path #11027
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
brew style
with your changes locally? (currently not possible on Apple Silicon)brew typecheck
with your changes locally? (currently not possible on Apple Silicon)brew tests
with your changes locally? (currently not possible on Apple Silicon)Context
When we introduced the completion cache mechanism for zsh about 2 years ago, we needed the path to the installed Taps for checking if the current completion cache should be invalidated. This is the relevant code:
brew/completions/zsh/_brew
Line 50 in 0ec1f04
But as you can see, the fallback value is hardcoded and often incorrect in more and more cases as users move to
/opt/homebrew
.Why it matters
The
HOMEBREW_REPOSITORY
variable is automatically defined in Homebrew scripts, but not outside of those scripts, in particular during execution of shell autocompletion scripts. As a result, the fallback is incorrect if a user has moved to/opt/homebrew
, and the cache is invalidated and recreated on each invocation, which is slow and defeats its purpose.Proposed solution
After discussing with @Rylan12 in #11023 (thanks again), we settled on the following:
This was chosen because it always resolves to the correct path (
/usr/local/Homebrew
or/opt/homebrew
), which no available env var likeHOMEBREW_PREFIX
is able to.This PR implements this solution on both the
_brew
file and theerb
template file. (edited)