2 # paclist - List all packages installed from a given repo
4 # Copyright (C) 2008 Dan McGee <dpmcgee@gmail.com>
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 my $progname = "paclist";
25 if ($#ARGV != 0 || $ARGV[0] eq "--help" || $ARGV[0] eq "-h") {
26 print "$progname - List all packages installed from a given repo\n";
27 print "Usage: $progname <repo>\n";
28 print "Example: $progname testing\n";
35 if ( $ARGV[0] eq "--version" || $ARGV[0] eq "-v") {
36 print "$progname version $version\n";
37 print "Copyright (C) 2008 Dan McGee\n";
41 # This hash table will be used to store pairs of ('name version', count) from
42 # the return of both pacman -Sl <repo> and pacman -Q output. We then check to
43 # see if a value was added twice (count = 2)- if so, we will print that package
44 # as it is both in the repo we queried and installed on our local system.
48 $output = `pacman -Sl $ARGV[0]`;
52 my @sync = split(/\n/, $output);
53 # sample output from pacman -Sl:
54 # testing foobar 1.0-1
56 my @info = split(/ /);
57 # we only want to store 'foobar 1.0-1' in our hash table
58 my $pkg = $info[1] . " " . $info[2];
62 $output = `pacman -Q`;
66 # sample output from pacman -Q:
68 my @local = split(/\n/, $output);
70 # store 'foobar 1.0-1' in our hash table
74 # run comparison check- if value was added twice, it was in the intersection
76 foreach $_ (keys %packages) {
77 if ($packages{$_} == 2) {
78 push @
{ \
@intersection }, $_;
82 # print our intersection, and bask in the glory and speed of perl
83 @intersection = sort @intersection;
84 foreach $_ (@intersection) {