aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
authorSamuel John2013-01-29 23:34:55 +0100
committerSamuel John2013-09-03 11:52:34 +0200
commitcf8f4ccc7616bc7a1d22cab6dc399f2cbc99c47e (patch)
tree67f077e765b766b1cd3f039745a0c037697f432a /Library/Homebrew
parent040bb3e7d15e5d453faec3e3071a74a5b5df8e3d (diff)
downloadhomebrew-cf8f4ccc7616bc7a1d22cab6dc399f2cbc99c47e.tar.bz2
brew search <user>/<repo> [substring]
For example `brew search homebrew/science` to get a list of all formulae from that tap, even if not yet tapped. `brew search <user>/<repo>/<substr>` or `brew search <user>/<repo> <substr>` to grep for `<substr>` inside of the tap `<user>/<repo>`.
Diffstat (limited to 'Library/Homebrew')
-rw-r--r--Library/Homebrew/cmd/search.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb
index f18f21ca3..b2febbdba 100644
--- a/Library/Homebrew/cmd/search.rb
+++ b/Library/Homebrew/cmd/search.rb
@@ -4,6 +4,12 @@ require 'utils'
require 'utils/json'
module Homebrew extend self
+
+ # A regular expession to capture the username (one or more char but no `/`,
+ # which has to be escaped like `\/`), repository, followed by an optional `/`
+ # and an optional query.
+ TAP_QUERY_REGEX = /^([^\/]+)\/([^\/]+)\/?(.+)?$/
+
def search
if ARGV.include? '--macports'
exec_browser "http://www.macports.org/ports.php?by=name&substr=#{ARGV.next}"
@@ -19,6 +25,23 @@ module Homebrew extend self
exec_browser "http://packages.ubuntu.com/search?keywords=#{ARGV.next}&searchon=names&suite=all&section=all"
elsif (query = ARGV.first).nil?
puts_columns Formula.names
+ elsif ARGV.first =~ TAP_QUERY_REGEX
+ # So look for user/repo/query or list all formulae by the tap
+ # we downcase to avoid case-insensitive filesystem issues.
+ user, repo, query = $1.downcase, $2.downcase, $3
+ tap_dir = HOMEBREW_LIBRARY/"Taps/#{user}-#{repo}"
+ # If, instead of `user/repo/query` the user wrote `user/repo query`:
+ query = ARGV[1] if query.nil?
+ if tap_dir.directory?
+ # There is a local tap already:
+ result = Dir["#{tap_dir}/*.rb"].map{ |f| File.basename(f).chomp('.rb') }
+ result = result.grep(query_regexp(query)) unless query.nil?
+ else
+ # Search online:
+ query = '' if query.nil?
+ result = search_tap(user, repo, query_regexp(query))
+ end
+ puts_columns result
else
rx = query_regexp(query)
local_results = search_formulae(rx)