2010-09-11 20:22:54 +01:00
|
|
|
require "formula"
|
2010-11-14 03:52:59 +00:00
|
|
|
require "blacklist"
|
2010-09-11 20:22:54 +01:00
|
|
|
|
|
|
|
module Homebrew extend self
|
|
|
|
def search
|
|
|
|
if ARGV.include? '--macports'
|
|
|
|
exec "open", "http://www.macports.org/ports.php?by=name&substr=#{ARGV.next}"
|
|
|
|
elsif ARGV.include? '--fink'
|
|
|
|
exec "open", "http://pdb.finkproject.org/pdb/browse.php?summary=#{ARGV.next}"
|
2010-11-14 03:52:59 +00:00
|
|
|
else
|
|
|
|
query = ARGV.first
|
2012-01-12 18:52:22 -06:00
|
|
|
rx = case query
|
|
|
|
when nil then ""
|
|
|
|
when %r{^/(.*)/$} then Regexp.new($1)
|
2012-01-11 20:49:08 -06:00
|
|
|
else
|
|
|
|
/.*#{Regexp.escape query}.*/i
|
|
|
|
end
|
|
|
|
|
|
|
|
search_results = search_brews rx
|
2010-11-14 03:52:59 +00:00
|
|
|
puts_columns search_results
|
2010-09-11 20:22:54 +01:00
|
|
|
|
2011-03-09 20:50:01 -08:00
|
|
|
if not query.to_s.empty? and $stdout.tty? and msg = blacklisted?(query)
|
2010-11-14 03:52:59 +00:00
|
|
|
unless search_results.empty?
|
|
|
|
puts
|
|
|
|
puts "If you meant `#{query}' precisely:"
|
|
|
|
puts
|
|
|
|
end
|
|
|
|
puts msg
|
|
|
|
end
|
2012-01-11 20:49:08 -06:00
|
|
|
|
|
|
|
if search_results.empty? and not blacklisted? query
|
|
|
|
pulls = GitHub.find_pull_requests rx
|
|
|
|
unless pulls.empty?
|
|
|
|
puts "Open pull requests matching \"#{query}\":", *pulls.map { |p| " #{p}" }
|
|
|
|
end
|
|
|
|
end
|
2010-11-14 03:52:59 +00:00
|
|
|
end
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
|
2012-01-11 20:49:08 -06:00
|
|
|
def search_brews rx
|
|
|
|
if rx.to_s.empty?
|
2010-09-11 20:22:54 +01:00
|
|
|
Formula.names
|
|
|
|
else
|
|
|
|
aliases = Formula.aliases
|
|
|
|
results = (Formula.names+aliases).grep rx
|
|
|
|
|
|
|
|
# Filter out aliases when the full name was also found
|
|
|
|
results.reject do |alias_name|
|
|
|
|
if aliases.include? alias_name
|
2010-12-31 11:00:15 -08:00
|
|
|
resolved_name = (HOMEBREW_REPOSITORY+"Library/Aliases"+alias_name).readlink.basename('.rb').to_s
|
2010-09-11 20:22:54 +01:00
|
|
|
results.include? resolved_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|