--prefix: shortlist only formulae

This commit is contained in:
Adrian Ho 2021-03-06 21:07:33 +08:00
parent a930e2b362
commit 548316ecc8
2 changed files with 7 additions and 4 deletions

View File

@ -17,10 +17,13 @@ homebrew-prefix() {
[ -z "$formula" ] && echo "$HOMEBREW_PREFIX" && return 0
local formula_path
if [ -f "$HOMEBREW_REPOSITORY/Library/Taps/homebrew/homebrew-core/${formula}.rb" ]; then
formula_path="$HOMEBREW_REPOSITORY/Library/Taps/homebrew/homebrew-core/${formula}.rb"
if [ -f "$HOMEBREW_REPOSITORY/Library/Taps/homebrew/homebrew-core/Formula/${formula}.rb" ]; then
formula_path="$HOMEBREW_REPOSITORY/Library/Taps/homebrew/homebrew-core/Formula/${formula}.rb"
else
formula_path="$(find "$HOMEBREW_REPOSITORY/Library/Taps" -name "${formula}.rb" -print -quit)"
formula_path="$(
shopt -s nullglob
echo "$HOMEBREW_REPOSITORY/Library/Taps"/*/*/{Formula/,HomebrewFormula/,}"${formula}.rb"
)"
fi
[ -z "$formula_path" ] && return 1

View File

@ -21,7 +21,7 @@ describe "brew --prefix" do
end
it "errors if the given Formula doesn't exist", :integration_test do
expect { brew "--prefix", "--installed", "nonexistent" }
expect { brew "--prefix", "nonexistent" }
.to output(/No available formula/).to_stderr
.and not_to_output.to_stdout
.and be_a_failure