Update pacsearch to work with new Qs/Ss output
Now that we have the '[installed]' text, update pacsearch to look for it and highlight it instead of the former '***' prefix. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
80f7c1707c
commit
3064f8d08d
1 changed files with 21 additions and 23 deletions
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
# pacsearch - Adds color and install information to a 'pacman -Ss' search
|
# pacsearch - Adds color and install information to a 'pacman -Ss' search
|
||||||
#
|
#
|
||||||
# Copyright (C) 2008 Dan McGee <dpmcgee@gmail.com>
|
# Copyright (C) 2008, 2010 Dan McGee <dpmcgee@gmail.com>
|
||||||
#
|
#
|
||||||
# Based off original shell script version:
|
# Based off original shell script version:
|
||||||
# Copyright (C) 2006-2007 Dan McGee <dpmcgee@gmail.com>
|
# Copyright (C) 2006-2007 Dan McGee <dpmcgee@gmail.com>
|
||||||
|
@ -39,7 +39,7 @@ if ($#ARGV lt 0 || $ARGV[0] eq "--help" || $ARGV[0] eq "-h") {
|
||||||
|
|
||||||
if ($ARGV[0] eq "--version" || $ARGV[0] eq "-v") {
|
if ($ARGV[0] eq "--version" || $ARGV[0] eq "-v") {
|
||||||
print "$progname version $version\n";
|
print "$progname version $version\n";
|
||||||
print "Copyright (C) 2006-2008 Dan McGee\n";
|
print "Copyright (C) 2006-2010 Dan McGee\n";
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,17 +53,18 @@ my $CLR6 = "\e[0;33m";
|
||||||
my $CLR7 = "\e[1;36m";
|
my $CLR7 = "\e[1;36m";
|
||||||
my $INST = "\e[1;31m";
|
my $INST = "\e[1;31m";
|
||||||
my $BASE = "\e[0m";
|
my $BASE = "\e[0m";
|
||||||
my $INSTMARK = $INST."***";
|
|
||||||
|
|
||||||
# color a "repo/pkgname pkgver" line based on the respository name
|
# color a "repo/pkgname pkgver" line based on the repository name
|
||||||
sub to_color {
|
sub to_color {
|
||||||
my $line = shift;
|
my $line = shift;
|
||||||
|
# get the installed text colored first
|
||||||
|
$line =~ s/(\[.*\]$)/$INST$1$BASE/;
|
||||||
|
# and now the repo and dealings
|
||||||
$line =~ s/(^core\/.*)/$CLR1$1$BASE/;
|
$line =~ s/(^core\/.*)/$CLR1$1$BASE/;
|
||||||
$line =~ s/(^extra\/.*)/$CLR2$1$BASE/;
|
$line =~ s/(^extra\/.*)/$CLR2$1$BASE/;
|
||||||
$line =~ s/(^community\/.*)/$CLR3$1$BASE/;
|
$line =~ s/(^community\/.*)/$CLR3$1$BASE/;
|
||||||
$line =~ s/(^testing\/.*)/$CLR4$1$BASE/;
|
$line =~ s/(^testing\/.*)/$CLR4$1$BASE/;
|
||||||
$line =~ s/(^unstable\/.*)/$CLR5$1$BASE/;
|
$line =~ s/(^community-testing\/.*)/$CLR5$1$BASE/;
|
||||||
$line =~ s/(^custom\/.*)/$CLR6$1$BASE/;
|
|
||||||
$line =~ s/(^local\/.*)/$CLR7$1$BASE/;
|
$line =~ s/(^local\/.*)/$CLR7$1$BASE/;
|
||||||
# any other unknown repository
|
# any other unknown repository
|
||||||
$line =~ s/(^[\w-]*\/.*)/$CLR6$1$BASE/;
|
$line =~ s/(^[\w-]*\/.*)/$CLR6$1$BASE/;
|
||||||
|
@ -83,10 +84,10 @@ if ($#syncpkgs >= 0) {
|
||||||
# counter var for packages, used here and in the query loop too
|
# counter var for packages, used here and in the query loop too
|
||||||
my $cnt = 0;
|
my $cnt = 0;
|
||||||
foreach $_ (@syncpkgs) {
|
foreach $_ (@syncpkgs) {
|
||||||
# we grab 3 fields here: repo, name/ver, and desc
|
# we grab 4 fields here: repo, name/ver, installed, and desc
|
||||||
my @pkgfields = /^(.*?)\/(.*?)\n(.*)$/s;
|
my @pkgfields = /^(.*?)\/(.*?) ?(\[.*\])?\n(.*)$/s;
|
||||||
# add a fourth field that will indicate install status
|
# since installed is optional, we should fill it in if necessary
|
||||||
push (@pkgfields, "");
|
$pkgfields[2] = "" if not defined $pkgfields[2];
|
||||||
# add a fifth field that indicates original order
|
# add a fifth field that indicates original order
|
||||||
push (@pkgfields, $cnt++);
|
push (@pkgfields, $cnt++);
|
||||||
# add each sync pkg by name/ver to a hash table for quick lookup
|
# add each sync pkg by name/ver to a hash table for quick lookup
|
||||||
|
@ -102,16 +103,13 @@ if ($#querypkgs >= 0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach $_ (@querypkgs) {
|
foreach $_ (@querypkgs) {
|
||||||
# we grab 3 fields here: repo, name/ver, and desc
|
# we grab 4 fields here: repo, name/ver, installed, and desc
|
||||||
my @pkgfields = /^(.*?)\/(.*?)\n(.*)$/s;
|
my @pkgfields = /^(.*?)\/(.*?) ?(\[.*\])?\n(.*)$/s;
|
||||||
|
# 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
|
# check if the package was listed in the sync out
|
||||||
# if it is we want to mark it with a *** marker
|
if (not exists $allpkgs{$pkgfields[1]}) {
|
||||||
if (exists $allpkgs{$pkgfields[1]}) {
|
$pkgfields[2] = "[installed]";
|
||||||
# mark it in our fourth field as installed
|
|
||||||
@{ $allpkgs{$pkgfields[1]} }[3] = $INSTMARK;
|
|
||||||
} else {
|
|
||||||
# add a fourth field that will indicate install status
|
|
||||||
push (@pkgfields, $INSTMARK);
|
|
||||||
# add a fifth field that indicates original order (after sync)
|
# add a fifth field that indicates original order (after sync)
|
||||||
push (@pkgfields, $cnt++);
|
push (@pkgfields, $cnt++);
|
||||||
# add our local-only package to the hash
|
# add our local-only package to the hash
|
||||||
|
@ -122,11 +120,11 @@ foreach $_ (@querypkgs) {
|
||||||
# sort by original order (the fifth field) and print
|
# sort by original order (the fifth field) and print
|
||||||
foreach $_ ( sort{ @{$allpkgs{$a}}[4] <=> @{$allpkgs{$b}}[4] } keys %allpkgs) {
|
foreach $_ ( sort{ @{$allpkgs{$a}}[4] <=> @{$allpkgs{$b}}[4] } keys %allpkgs) {
|
||||||
my @v = @{$allpkgs{$_}};
|
my @v = @{$allpkgs{$_}};
|
||||||
my $line = "$v[0]/$v[1]";
|
my $line = "$v[0]/$v[1] $v[2]";
|
||||||
$line = to_color($line);
|
$line = to_color($line);
|
||||||
# print install marker + colorized "repo/pkgname pkgver" string
|
# print colorized "repo/pkgname pkgver" string with possible installed text
|
||||||
print "$v[3]$line\n";
|
print "$line\n";
|
||||||
print "$v[2]\n";
|
print "$v[3]\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
#vim: set noet:
|
#vim: set noet:
|
||||||
|
|
Loading…
Add table
Reference in a new issue