On 14-02-10 11:09:25, Andrew Gregory wrote:
On 02/09/14 at 07:41pm, Pierre Neidhardt wrote:
Previously only one pattern was allowed.
$ pacsearch foo bar Search for packages containing 'foo bar'.
$ pacman -Ss foo bar Search for packages containing both 'foo' and 'bar'.
Note that removing the quotes from the call was not enough since $ pacsearch 'foo|bar' would then fail.
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-)
diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index df0d62d..0dad366 100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -92,48 +92,38 @@ sub print_pkg { print "$MAGENTA"; } print "$v[0]/$RESET$BOLD$v[1] $GREEN$v[2]$BLUE$v[3]$CYAN$v[4]$RESET\n"; - print "$v[5]\n"; + print "$v[5]"; }
my %allpkgs = (); my @pkglist = ();
-my $syncout = `pacman -Ss '@ARGV'`; -# split each sync search entry into its own array entry -my @syncpkgs = split(/\n^(?=\w)/m, $syncout); -# remove the extra \n from the last desc entry -if ($#syncpkgs >= 0) { - chomp($syncpkgs[$#syncpkgs]); -} - -foreach $_ (@syncpkgs) { +open (my $syncout, '-|', 'pacman', '-Ss', @ARGV) or exit;
If we can't run pacman we need to print an error message and exit non-zero.
'open' already prints an error message. Writing +open (my $syncout, '-|', 'pacman', '-Ss', @ARGV) or die "pacman not found: $!"; prints 2 times the same error.
+while ( readline($syncout) ) { # We grab the following fields: repo, name, ver, group, installed, and # desc. We grab leading space for 'group' and 'installed' so that we do not # need to test if non-empty when printing. - my @pkgfields = /^(.*?)\/(.*?) (.*?)( \(.*?\))?( \[.*\])?\n(.*)$/s; + my @pkgfields = /^(.*?)\/(.*?) (.*?)( \(.*?\))?( \[.*\])?$/s; + my $desc = readline($syncout);
This still needs to be moved after the match check. If we can't parse the previous line we have no way of knowing that the next one is actually a description.
Right, I'll fix this. -- Pierre Neidhardt I got this powdered water -- now I don't know what to add. -- Steven Wright