diff options
Diffstat (limited to 'Library/Homebrew/cmd/search.rb')
| -rw-r--r-- | Library/Homebrew/cmd/search.rb | 23 |
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§ion=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) |
