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>`.
This commit is contained in:
Samuel John 2013-01-29 23:34:55 +01:00
parent a260bb1906
commit 9b755e5ad2
3 changed files with 49 additions and 8 deletions

View File

@ -30,10 +30,11 @@ Note that these flags should only appear after a command.
* `list`: * `list`:
List all installed formulae. List all installed formulae.
* `search`, `-S` <text>|/<text>/: * `search` <text>|/<text>/:
Perform a substring search of formula names for <text>. If <text> is Perform a substring search of formula names for <text>. If <text> is
surrounded with slashes, then it is interpreted as a regular expression. surrounded with slashes, then it is interpreted as a regular expression.
If no search term is given, all available formula are displayed. The search for <text> is extended online to some popular taps.
If no search term is given, all locally available formulae are listed.
## COMMANDS ## COMMANDS
@ -272,10 +273,19 @@ Note that these flags should only appear after a command.
If `--force` is passed, and there are multiple versions of <formula> If `--force` is passed, and there are multiple versions of <formula>
installed, delete all installed versions. installed, delete all installed versions.
* `search`, `-S` <text>|/<text>/: * `search`, `-S`:
Display all locally available formulae for brewing (including tapped ones).
No online search is performed if called without arguments.
* `search`, `-S` <tap>:
Display all formulae in a <tap>, even if not yet tapped.
<tap> is of the form <user>/<repo>, e.g. `brew search homebrew/dupes`.
* `search`, `-S` [<tap>] <text>|/<text>/:
Perform a substring search of formula names for <text>. If <text> is Perform a substring search of formula names for <text>. If <text> is
surrounded with slashes, then it is interpreted as a regular expression. surrounded with slashes, then it is interpreted as a regular expression.
If no search term is given, all available formula are displayed. The search for <text> is extended online to some popular taps.
If a <tap> is specified, the search is restricted to it.
* `search --debian`|`--fedora`|`--fink`|`--macports`|`--opensuse`|`--ubuntu` <text>: * `search --debian`|`--fedora`|`--fink`|`--macports`|`--opensuse`|`--ubuntu` <text>:
Search for <text> in the given package manager's list. Search for <text> in the given package manager's list.

View File

@ -4,6 +4,12 @@ require 'utils'
require 'utils/json' require 'utils/json'
module Homebrew extend self 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 def search
if ARGV.include? '--macports' if ARGV.include? '--macports'
exec_browser "http://www.macports.org/ports.php?by=name&substr=#{ARGV.next}" 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" exec_browser "http://packages.ubuntu.com/search?keywords=#{ARGV.next}&searchon=names&suite=all&section=all"
elsif (query = ARGV.first).nil? elsif (query = ARGV.first).nil?
puts_columns Formula.names 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 else
rx = query_regexp(query) rx = query_regexp(query)
local_results = search_formulae(rx) local_results = search_formulae(rx)

View File

@ -38,8 +38,8 @@ Fetch the newest version of Homebrew from GitHub using \fBgit\fR(1)\.
List all installed formulae\. List all installed formulae\.
. .
.TP .TP
\fBsearch\fR, \fB\-S\fR \fItext\fR|/\fItext\fR/ \fBsearch\fR \fItext\fR|/\fItext\fR/
Perform a substring search of formula names for \fItext\fR\. If \fItext\fR is surrounded with slashes, then it is interpreted as a regular expression\. If no search term is given, all available formula are displayed\. Perform a substring search of formula names for \fItext\fR\. If \fItext\fR is surrounded with slashes, then it is interpreted as a regular expression\. The search for \fItext\fR is extended online to some popular taps\. If no search term is given, all locally available formulae are listed\.
. .
.SH "COMMANDS" .SH "COMMANDS"
. .
@ -298,8 +298,16 @@ Uninstall \fIformula\fR\.
If \fB\-\-force\fR is passed, and there are multiple versions of \fIformula\fR installed, delete all installed versions\. If \fB\-\-force\fR is passed, and there are multiple versions of \fIformula\fR installed, delete all installed versions\.
. .
.TP .TP
\fBsearch\fR, \fB\-S\fR \fItext\fR|/\fItext\fR/ \fBsearch\fR, \fB\-S\fR
Perform a substring search of formula names for \fItext\fR\. If \fItext\fR is surrounded with slashes, then it is interpreted as a regular expression\. If no search term is given, all available formula are displayed\. Display all locally available formulae for brewing (including tapped ones)\. No online search is performed if called without arguments\.
.
.TP
\fBsearch\fR, \fB\-S\fR \fItap\fR
Display all formulae in a \fItap\fR, even if not yet tapped\. \fItap\fR is of the form \fIuser\fR/\fIrepo\fR, e\.g\. \fBbrew search homebrew/dupes\fR\.
.
.TP
\fBsearch\fR, \fB\-S\fR [\fItap\fR] \fItext\fR|/\fItext\fR/
Perform a substring search of formula names for \fItext\fR\. If \fItext\fR is surrounded with slashes, then it is interpreted as a regular expression\. The search for \fItext\fR is extended online to some popular taps\. If a \fItap\fR is specified, the search is restricted to it\.
. .
.TP .TP
\fBsearch \-\-debian\fR|\fB\-\-fedora\fR|\fB\-\-fink\fR|\fB\-\-macports\fR|\fB\-\-opensuse\fR|\fB\-\-ubuntu\fR \fItext\fR \fBsearch \-\-debian\fR|\fB\-\-fedora\fR|\fB\-\-fink\fR|\fB\-\-macports\fR|\fB\-\-opensuse\fR|\fB\-\-ubuntu\fR \fItext\fR