[pacman-dev] [PATCH 1/7] Copyright year bump
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index 624f201..63435f0 100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -1,7 +1,7 @@ #!/usr/bin/perl # pacsearch - Adds color and install information to a 'pacman -Ss' search # -# Copyright (C) 2008-2011 Dan McGee <dan@archlinux.org> +# Copyright (C) 2008-2014 Dan McGee <dan@archlinux.org> # # Based off original shell script version: # Copyright (C) 2006-2007 Dan McGee <dan@archlinux.org> @@ -36,7 +36,7 @@ sub usage { sub version { printf "%s %s\n", $myname, $myver; - print "Copyright (C) 2008-2011 Dan McGee <dan\@archlinux.org>\n\n"; + print "Copyright (C) 2008-2014 Dan McGee <dan\@archlinux.org>\n\n"; print "Based off original shell script version:\n"; print "Copyright (C) 2006-2007 Dan McGee <dan\@archlinux.org>\n"; } -- 1.8.5.3
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index 63435f0..f2b75f6 100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -1,5 +1,5 @@ #!/usr/bin/perl -# pacsearch - Adds color and install information to a 'pacman -Ss' search +# pacsearch - Perform a pacman search using both the local and the sync databases # # Copyright (C) 2008-2014 Dan McGee <dan@archlinux.org> # @@ -29,7 +29,7 @@ my $myver = '@PACKAGE_VERSION@'; sub usage { print "$myname (pacman) v$myver\n\n"; - print "Add color and install information to a 'pacman -Ss' search\n\n"; + print "Perform a pacman search using both the local and the sync databases.\n\n"; print "Usage: $myname <pattern>\n\n"; print "Example: $myname ^gnome\n"; } -- 1.8.5.3
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index f2b75f6..69c7c0f 100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -65,6 +65,9 @@ my $CLR7 = "\e[1;36m"; my $INST = "\e[1;31m"; my $BASE = "\e[0m"; +# localization +my $LC_INSTALLED = `gettext pacman installed`; + # color a "repo/pkgname pkgver" line based on the repository name sub to_color { my $line = shift; @@ -128,7 +131,7 @@ foreach $_ (@querypkgs) { $pkgfields[2] = "" if not defined $pkgfields[2]; # check if the package was listed in the sync out if (not exists $allpkgs{$pkgfields[1]}) { - $pkgfields[2] = "[installed]"; + $pkgfields[2] = "[$LC_INSTALLED]"; # add a fifth field that indicates original order (after sync) push (@pkgfields, $cnt++); # add our local-only package to the hash -- 1.8.5.3
Previously pkgname and pkgver were stored together, and group was ignored. Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index 69c7c0f..57901ee 100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -99,16 +99,17 @@ if ($#syncpkgs >= 0) { # counter var for packages, used here and in the query loop too my $cnt = 0; foreach $_ (@syncpkgs) { - # we grab 4 fields here: repo, name/ver, installed, and desc - my @pkgfields = /^(.*?)\/(.*?) ?(\[.*\])?\n(.*)$/s; + # we grab the following fields: repo, name, ver, group, installed, and desc + my @pkgfields = /^(.*?)\/(.*?) (.*?) ?(\(.*?\))? ?(\[.*\])?\n(.*)$/s; if(not @pkgfields) { # skip any non-matching line and just print it for the user print $_, "\n"; next; } - # since installed is optional, we should fill it in if necessary - $pkgfields[2] = "" if not defined $pkgfields[2]; - # add a fifth field that indicates original order + # since 'group' and 'installed' are optional, we should fill it in if necessary + $pkgfields[3] = "" if not defined $pkgfields[3]; + $pkgfields[4] = "" if not defined $pkgfields[4]; + # add a last field that indicates original order push (@pkgfields, $cnt++); # add each sync pkg by name/ver to a hash table for quick lookup $allpkgs{$pkgfields[1]} = [ @pkgfields ]; @@ -123,30 +124,33 @@ if ($#querypkgs >= 0) { } foreach $_ (@querypkgs) { - # we grab 4 fields here: repo, name/ver, installed, and desc - my @pkgfields = /^(.*?)\/(.*?) ?(\[.*\])?\n(.*)$/s; + # we grab the following fields: repo, name, ver, group, installed, and desc + my @pkgfields = /^(.*?)\/(.*?) (.*?) ?(\(.*?\))? ?(\[.*\])?\n(.*)$/s; + # my @pkgfields = /^(.*?)\/(.*?) ?(\[.*\])?\n(.*)$/s; # skip any non-matching line next if not defined $pkgfields[1]; - # since installed is optional, we should fill it in if necessary - $pkgfields[2] = "" if not defined $pkgfields[2]; # check if the package was listed in the sync out if (not exists $allpkgs{$pkgfields[1]}) { - $pkgfields[2] = "[$LC_INSTALLED]"; - # add a fifth field that indicates original order (after sync) + # since 'group' is optional, we should fill it in if necessary + $pkgfields[3] = "" if not defined $pkgfields[3]; + $pkgfields[4] = "[$LC_INSTALLED]"; + # add a last field that indicates original order (after sync) push (@pkgfields, $cnt++); # add our local-only package to the hash $allpkgs{$pkgfields[1]} = [ @pkgfields ]; } } -# sort by original order (the fifth field) and print -foreach $_ ( sort{ @{$allpkgs{$a}}[4] <=> @{$allpkgs{$b}}[4] } keys %allpkgs) { +# sort by original order (the last field) and print +foreach $_ ( sort{ @{$allpkgs{$a}}[6] <=> @{$allpkgs{$b}}[6] } keys %allpkgs) { my @v = @{$allpkgs{$_}}; my $line = "$v[0]/$v[1] $v[2]"; + $line .= " $v[3]" if $v[3] ne ""; + $line .= " $v[4]" if $v[4] ne ""; $line = to_color($line); - # print colorized "repo/pkgname pkgver" string with possible installed text + # print colorized "repo/pkgname pkgver ..." string with possible installed text print "$line\n"; - print "$v[3]\n"; + print "$v[5]\n"; } #vim: set noet: -- 1.8.5.3
On 23/01/14 09:07, Pierre Neidhardt wrote:
Previously pkgname and pkgver were stored together, and group was ignored.
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> ---
Fine - I changed the commit message as group was printed with the old pacsearch: pacsearch: Explicitly extract group information Also store pkgname and pkgver separately.
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index 57901ee..d03778e 100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -23,6 +23,7 @@ use strict; use warnings; +use Term::ANSIColor; my $myname = 'pacsearch'; my $myver = '@PACKAGE_VERSION@'; @@ -55,15 +56,15 @@ if ($ARGV[0] eq "--version" || $ARGV[0] eq "-V") { } # define our colors to use when printing -my $CLR1 = "\e[0;34m"; -my $CLR2 = "\e[0;32m"; -my $CLR3 = "\e[0;35m"; -my $CLR4 = "\e[0;36m"; -my $CLR5 = "\e[0;31m"; -my $CLR6 = "\e[0;33m"; -my $CLR7 = "\e[1;36m"; -my $INST = "\e[1;31m"; -my $BASE = "\e[0m"; +my($BLUE, $CYAN, $GREEN, $MAGENTA, $RED, $YELLOW, $BOLD, $RESET); +$BLUE = color('blue'); +$CYAN = color('cyan'); +$GREEN = color('green'); +$MAGENTA = color('magenta'); +$RED = color('red'); +$YELLOW = color('yellow'); +$BOLD = color('bold'); +$RESET = color('reset'); # localization my $LC_INSTALLED = `gettext pacman installed`; @@ -72,17 +73,17 @@ my $LC_INSTALLED = `gettext pacman installed`; sub to_color { my $line = shift; # get the installed text colored first - $line =~ s/(\[.*\]$)/$INST$1$BASE/; + $line =~ s/(\[.*\]$)/$CYAN$1$RESET/; # and now the repo and dealings - $line =~ s/(^core\/.*)/$CLR1$1$BASE/; - $line =~ s/(^extra\/.*)/$CLR2$1$BASE/; - $line =~ s/(^community\/.*)/$CLR3$1$BASE/; - $line =~ s/(^testing\/.*)/$CLR4$1$BASE/; - $line =~ s/(^community-testing\/.*)/$CLR5$1$BASE/; - $line =~ s/(^multilib\/.*)/$CLR6$1$BASE/; - $line =~ s/(^local\/.*)/$CLR7$1$BASE/; + $line =~ s/(^core\/.*)/$MAGENTA$1$RESET/; + $line =~ s/(^extra\/.*)/$MAGENTA$1$RESET/; + $line =~ s/(^community\/.*)/$MAGENTA$1$RESET/; + $line =~ s/(^testing\/.*)/$MAGENTA$1$RESET/; + $line =~ s/(^community-testing\/.*)/$MAGENTA$1$RESET/; + $line =~ s/(^multilib\/.*)/$MAGENTA$1$RESET/; + $line =~ s/(^local\/.*)/$RED$1$RESET/; # any other unknown repository - $line =~ s/(^[\w-]*\/.*)/$CLR6$1$BASE/; + $line =~ s/(^[\w-]*\/.*)/$RED$1$RESET/; return $line; } -- 1.8.5.3
No more per-repo coloring: this was not Arch-agnostic, and there is no reasonable, simple way to color repos in a consistant manner with only 6 colors. 'local' is in red: this way we benefit from the pacman -Ss && pacman -Qs combo. to_color subroutine: it takes an array instead of a string, this is faster and simpler. Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index d03778e..180694b 100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -69,21 +69,20 @@ $RESET = color('reset'); # localization my $LC_INSTALLED = `gettext pacman installed`; -# color a "repo/pkgname pkgver" line based on the repository name +# Color a "repo/pkgname pkgver (groups) [installed]" line. +# We try to stick to pacman colors. sub to_color { - my $line = shift; - # get the installed text colored first - $line =~ s/(\[.*\]$)/$CYAN$1$RESET/; - # and now the repo and dealings - $line =~ s/(^core\/.*)/$MAGENTA$1$RESET/; - $line =~ s/(^extra\/.*)/$MAGENTA$1$RESET/; - $line =~ s/(^community\/.*)/$MAGENTA$1$RESET/; - $line =~ s/(^testing\/.*)/$MAGENTA$1$RESET/; - $line =~ s/(^community-testing\/.*)/$MAGENTA$1$RESET/; - $line =~ s/(^multilib\/.*)/$MAGENTA$1$RESET/; - $line =~ s/(^local\/.*)/$RED$1$RESET/; - # any other unknown repository - $line =~ s/(^[\w-]*\/.*)/$RED$1$RESET/; + my @v = @_; + my $line = "$RESET$BOLD"; + if ( "$v[0]" eq "local" ) { + $line .= "$RED"; + } else { + $line .= "$MAGENTA"; + } + $line .= "$v[0]/$RESET$BOLD$v[1] $GREEN$v[2]"; + $line .= " $BLUE$v[3]" if $v[3] ne ""; + $line .= " $CYAN$v[4]" if $v[4] ne ""; + $line .= " $RESET"; return $line; } @@ -145,10 +144,7 @@ foreach $_ (@querypkgs) { # sort by original order (the last field) and print foreach $_ ( sort{ @{$allpkgs{$a}}[6] <=> @{$allpkgs{$b}}[6] } keys %allpkgs) { my @v = @{$allpkgs{$_}}; - my $line = "$v[0]/$v[1] $v[2]"; - $line .= " $v[3]" if $v[3] ne ""; - $line .= " $v[4]" if $v[4] ne ""; - $line = to_color($line); + my $line = to_color(@v); # print colorized "repo/pkgname pkgver ..." string with possible installed text print "$line\n"; print "$v[5]\n"; -- 1.8.5.3
On 01/23/14 at 12:07am, Pierre Neidhardt wrote:
No more per-repo coloring: this was not Arch-agnostic, and there is no reasonable, simple way to color repos in a consistant manner with only 6 colors.
'local' is in red: this way we benefit from the pacman -Ss && pacman -Qs combo.
to_color subroutine: it takes an array instead of a string, this is faster and simpler.
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-)
If we use pacman's color theme and remove per-repo coloring does this script still do anything worth keeping it around and fixing its bugs (try `pacsearch pacman mirrorlist`)? All that's left is searching both -Ss and -Qs, recoloring "local/" red, adding "[installed]" to -Qs entries, and hiding -Qs entries that are also in -Ss. All but the last can be accomplished in a few lines of bash using sed.
On 14-01-23 08:38:22, Andrew Gregory wrote:
On 01/23/14 at 12:07am, Pierre Neidhardt wrote:
No more per-repo coloring: this was not Arch-agnostic, and there is no reasonable, simple way to color repos in a consistant manner with only 6 colors.
'local' is in red: this way we benefit from the pacman -Ss && pacman -Qs combo.
to_color subroutine: it takes an array instead of a string, this is faster and simpler.
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-)
If we use pacman's color theme and remove per-repo coloring does this script still do anything worth keeping it around and fixing its bugs (try `pacsearch pacman mirrorlist`)? All that's left is searching both -Ss and -Qs, recoloring "local/" red, adding "[installed]" to -Qs entries, and hiding -Qs entries that are also in -Ss. All but the last can be accomplished in a few lines of bash using sed.
That was what I suggested in the first place a few days ago in my 'request for removal' mail. But Dan finds the combo of -Ss and -Qs quite useful and pointed quite good reasons to keep it. This script is tiny, right, but not enough to be a one-liner (the "duplicate entry removal" needs a hash table and some parsing). Besides when you do it with sed/awk, you lose the coloring. And with sed/awk it's hard to sort without another call to 'sort', which does not save time. All these reasons are good enough to have this script. If I understood you correctly, `pacsearch pacman mirrorlist` is not a bug. pacsearch's argument is a pattern, not package names. See pacsearch -h. -- Pierre Neidhardt What the large print giveth, the small print taketh away.
On 01/23/14 at 02:58pm, Pierre Neidhardt wrote:
On 14-01-23 08:38:22, Andrew Gregory wrote:
On 01/23/14 at 12:07am, Pierre Neidhardt wrote:
No more per-repo coloring: this was not Arch-agnostic, and there is no reasonable, simple way to color repos in a consistant manner with only 6 colors.
'local' is in red: this way we benefit from the pacman -Ss && pacman -Qs combo.
to_color subroutine: it takes an array instead of a string, this is faster and simpler.
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-)
If we use pacman's color theme and remove per-repo coloring does this script still do anything worth keeping it around and fixing its bugs (try `pacsearch pacman mirrorlist`)? All that's left is searching both -Ss and -Qs, recoloring "local/" red, adding "[installed]" to -Qs entries, and hiding -Qs entries that are also in -Ss. All but the last can be accomplished in a few lines of bash using sed.
That was what I suggested in the first place a few days ago in my 'request for removal' mail. But Dan finds the combo of -Ss and -Qs quite useful and pointed quite good reasons to keep it.
I'm not disputing the usefulness of searching -Qs and -Ss at the same time, but that alone is a one line bash function. There's no point in keeping this script if that's all we care about.
This script is tiny, right, but not enough to be a one-liner (the "duplicate entry removal" needs a hash table and some parsing). Besides when you do it with sed/awk, you lose the coloring. And with sed/awk it's hard to sort without another call to 'sort', which does not save time. All these reasons are good enough to have this script.
pacsearch does not sort its results and you can still have color with sed/awk with --color=always.
If I understood you correctly, `pacsearch pacman mirrorlist` is not a bug. pacsearch's argument is a pattern, not package names. See pacsearch -h.
pacman mirrorlist is not the name of a package, those are two separate search terms that pacsearch needlessly combines into a single term when it passes them to pacman. apg
On 14-01-23 10:03:57, Andrew Gregory wrote:
On 01/23/14 at 02:58pm, Pierre Neidhardt wrote:
On 14-01-23 08:38:22, Andrew Gregory wrote:
On 01/23/14 at 12:07am, Pierre Neidhardt wrote:
No more per-repo coloring: this was not Arch-agnostic, and there is no reasonable, simple way to color repos in a consistant manner with only 6 colors.
'local' is in red: this way we benefit from the pacman -Ss && pacman -Qs combo.
to_color subroutine: it takes an array instead of a string, this is faster and simpler.
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-)
If we use pacman's color theme and remove per-repo coloring does this script still do anything worth keeping it around and fixing its bugs (try `pacsearch pacman mirrorlist`)? All that's left is searching both -Ss and -Qs, recoloring "local/" red, adding "[installed]" to -Qs entries, and hiding -Qs entries that are also in -Ss. All but the last can be accomplished in a few lines of bash using sed.
...
This script is tiny, right, but not enough to be a one-liner (the "duplicate entry removal" needs a hash table and some parsing). Besides when you do it with sed/awk, you lose the coloring. And with sed/awk it's hard to sort without another call to 'sort', which does not save time. All these reasons are good enough to have this script.
pacsearch does not sort its results and you can still have color with sed/awk with --color=always.
I'm not sure that's a good solution, since the parsing gets tricky with all the colors into the strings. Try this: $ pacman -Ss pacman --color=always | awk '/core\/pacman/' <no result> $ pacman -Ss pacman | awk '/core\/pacman/' core/pacman 4.1.2-5 (base base-devel) [installerad] core/pacman-mirrorlist 20140107-1 [installerad]
If I understood you correctly, `pacsearch pacman mirrorlist` is not a bug. pacsearch's argument is a pattern, not package names. See pacsearch -h.
pacman mirrorlist is not the name of a package, those are two separate search terms that pacsearch needlessly combines into a single term when it passes them to pacman.
apg
Actually I was thinking this behaviour is a feature, for instance to find two words in a description. But pacman does not behave this way. $ pacman -Ss 'based package' core/pacman 4.1.2-5 (base base-devel) [installerad] A library-based package manager with dependency support $ pacman -Ss based package core/pacman 4.1.2-5 (base base-devel) [installerad] A library-based package manager with dependency support community/qcad 3.4.5.0-2 A 2D CAD package based upon Qt $ pacsearch based package core/pacman 4.1.2-5 (base base-devel) [installerad] A library-based package manager with dependency support I've just fixed it, it's a trivial bug. Thanks for pointing this out. -- Pierre Neidhardt The District of Columbia has a law forbidding you to exert pressure on a balloon and thereby cause a whistling sound on the streets.
Signed-off-by: Pierre Neidhardt <ambrevar@gmail.com> --- contrib/pacsearch.in | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/contrib/pacsearch.in b/contrib/pacsearch.in index 180694b..21043d4 100644 --- a/contrib/pacsearch.in +++ b/contrib/pacsearch.in @@ -19,8 +19,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -#TODO: colors flag on commandline - use strict; use warnings; use Term::ANSIColor; @@ -31,7 +29,9 @@ my $myver = '@PACKAGE_VERSION@'; sub usage { print "$myname (pacman) v$myver\n\n"; print "Perform a pacman search using both the local and the sync databases.\n\n"; - print "Usage: $myname <pattern>\n\n"; + print "Usage: $myname [-n] <pattern>\n\n"; + print "Options:\n"; + print " -n, --nocolor: turn off coloring\n\n"; print "Example: $myname ^gnome\n"; } @@ -55,16 +55,28 @@ if ($ARGV[0] eq "--version" || $ARGV[0] eq "-V") { exit 0; } -# define our colors to use when printing +# define formatting variables my($BLUE, $CYAN, $GREEN, $MAGENTA, $RED, $YELLOW, $BOLD, $RESET); -$BLUE = color('blue'); -$CYAN = color('cyan'); -$GREEN = color('green'); -$MAGENTA = color('magenta'); -$RED = color('red'); -$YELLOW = color('yellow'); -$BOLD = color('bold'); -$RESET = color('reset'); +if ($ARGV[0] eq "--nocolor" || $ARGV[0] eq "-n") { + shift; + $BLUE = ""; + $CYAN = ""; + $GREEN = ""; + $MAGENTA = ""; + $RED = ""; + $YELLOW = ""; + $BOLD = ""; + $RESET = ""; +} else { + $BLUE = color('blue'); + $CYAN = color('cyan'); + $GREEN = color('green'); + $MAGENTA = color('magenta'); + $RED = color('red'); + $YELLOW = color('yellow'); + $BOLD = color('bold'); + $RESET = color('reset'); +} # localization my $LC_INSTALLED = `gettext pacman installed`; -- 1.8.5.3
participants (3)
-
Allan McRae
-
Andrew Gregory
-
Pierre Neidhardt