Skip to content

Commit c5bec4a

Browse files
committed
initial
0 parents  commit c5bec4a

File tree

6 files changed

+305
-0
lines changed

6 files changed

+305
-0
lines changed

LICENSE

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
# Copyright (c) 2019-2022 Aaron Beiber <[email protected]>
3+
# Copyright (c) 2010 Marc Espie <[email protected]>
4+
*
5+
* Permission to use, copy, modify, and distribute this software for any
6+
* purpose with or without fee is hereby granted, provided that the above
7+
* copyright notice and this permission notice appear in all copies.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16+
*/

Makefile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MAN= pkg.8
2+
SCRIPT= pkg.pl
3+
4+
BINDIR?= /usr/local/sbin
5+
MANDIR?= /usr/local/man/man
6+
7+
realinstall:
8+
${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
9+
${.CURDIR}/${SCRIPT} ${DESTDIR}${BINDIR}/pkg
10+
11+
readme: pkg.8
12+
mandoc -T markdown pkg.8 >README.md
13+
14+
regress: check-n-tidy
15+
16+
check-n-tidy:
17+
@perl -c pkg.pl
18+
@perltidy pkg.pl -st | diff -q pkg.pl -
19+
@mandoc -T lint -W style pkg.8
20+
21+
.include <bsd.prog.mk>

README.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
PKG(8) - System Manager's Manual
2+
3+
# NAME
4+
5+
**pkg** - a wraper for OpenBSD's pkg\* tools
6+
7+
# SYNOPSIS
8+
9+
**pkg**
10+
\[*delete*&nbsp;*package*]
11+
\[*install*&nbsp;*package*]
12+
\[*info*&nbsp;*package*]
13+
\[*pathinfo*&nbsp;*pkgpath*]
14+
\[*search*&nbsp;*string*]
15+
16+
# DESCRIPTION
17+
18+
**pkg**
19+
is a
20+
perl(1)
21+
script that allows easier package management and more extensive searching.
22+
23+
**pkg**
24+
uses
25+
sqlports(5) for quicker, full text searching of COMMENT and DESCR fields.
26+
27+
The options are as follows:
28+
29+
*delete package*
30+
31+
> Deletes
32+
> **package**
33+
34+
*install package*
35+
36+
*info package*
37+
38+
*pathinfo package*
39+
40+
*search string*
41+
42+
> Search a packages COMMENT and DESCR for an arbitrary string.
43+
> **pkg**
44+
45+
# AUTHORS
46+
47+
**pkg**
48+
49+
OpenBSD 7.1 - April 7, 2022

pkg.8

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
.\" $OpenBSD$
2+
.\"
3+
.\" Copyright (c) 2022 Aaron Bieber <[email protected]>
4+
.\"
5+
.\" Permission to use, copy, modify, and distribute this software for any
6+
.\" purpose with or without fee is hereby granted, provided that the above
7+
.\" copyright notice and this permission notice appear in all copies.
8+
.\"
9+
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16+
.\"
17+
.Dd April 7, 2022
18+
.Dt PKG 8
19+
.Os
20+
.Sh NAME
21+
.Nm pkg
22+
.Nd a wraper for OpenBSD's pkg* tools
23+
.Sh SYNOPSIS
24+
.Nm
25+
.Op Ar delete Ar package
26+
.Op Ar install Ar package
27+
.Op Ar info Ar package
28+
.Op Ar pathinfo Ar pkgpath
29+
.Op Ar search Ar string
30+
.Sh DESCRIPTION
31+
.Nm
32+
is a
33+
.Xr perl 1
34+
script that allows easier package management and more extensive searching.
35+
.Pp
36+
.Nm
37+
uses
38+
.Xr sqlports 5 for quicker, full text searching of COMMENT and DESCR fields.
39+
.Pp
40+
The options are as follows:
41+
.Bl -tag -width Ds
42+
.It Ar delete package
43+
Deletes
44+
.Nm package
45+
.
46+
.It Ar install package
47+
.It Ar info package
48+
.It Ar pathinfo package
49+
.It Ar search string
50+
Search a packages COMMENT and DESCR for an arbitrary string.
51+
.Nm
52+
.El
53+
.Sh AUTHORS
54+
.An -nosplit
55+
.Nm

pkg.pl

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
#! /usr/bin/perl
2+
# ex:ts=8 sw=4:
3+
#
4+
# Copyright (c) 2019-2022 Aaron Beiber <[email protected]>
5+
# Copyright (c) 2010 Marc Espie <[email protected]>
6+
#
7+
# Permission to use, copy, modify, and distribute this software for any
8+
# purpose with or without fee is hereby granted, provided that the above
9+
# copyright notice and this permission notice appear in all copies.
10+
#
11+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17+
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18+
19+
use strict;
20+
use warnings;
21+
use DBI;
22+
23+
$| = 1;
24+
25+
my @l = qw(add check create delete info search pkgname);
26+
my %a = (
27+
"install" => "add",
28+
"i" => "add",
29+
"rm" => "delete",
30+
"del" => "delete",
31+
32+
"inf" => "info",
33+
"s" => "search",
34+
"pi" => "pathinfo"
35+
);
36+
37+
my $srcDBfile = '/usr/local/share/sqlports';
38+
my $dbfile = '/tmp/sqlports.fts';
39+
my $dbh;
40+
41+
sub run_sql {
42+
my ( $dbh, $sql ) = @_;
43+
44+
my $sth = $dbh->prepare($sql) or die $dbh->errstr . "\n$sql\n";
45+
$sth->execute() or die $dbh->errstr;
46+
return $sth;
47+
}
48+
49+
if ( !-e $dbfile ) {
50+
print STDERR "Creating full text database...";
51+
my $dbh = DBI->connect( "dbi:SQLite:dbname=:memory:", "", "" );
52+
$dbh->sqlite_backup_from_file($srcDBfile)
53+
or die "Can't copy sqlports to memory!";
54+
run_sql(
55+
$dbh, q{
56+
CREATE VIRTUAL TABLE
57+
ports_fts
58+
USING fts5(
59+
FULLPKGNAME,
60+
FULLPKGPATH,
61+
COMMENT,
62+
DESCRIPTION);
63+
}
64+
);
65+
run_sql(
66+
$dbh, q{
67+
INSERT INTO
68+
ports_fts
69+
(FULLPKGNAME, FULLPKGPATH, COMMENT, DESCRIPTION)
70+
select
71+
FULLPKGNAME,
72+
FULLPKGPATH,
73+
COMMENT,
74+
DESCR_CONTENTS
75+
FROM Ports;
76+
}
77+
);
78+
79+
$dbh->sqlite_backup_to_file($dbfile)
80+
or die "Can't copy sqlports to memory!";
81+
$dbh->disconnect();
82+
print STDERR "Done.\n";
83+
}
84+
85+
$dbh = DBI->connect( "dbi:SQLite:dbname=$dbfile", "", "" );
86+
87+
sub run {
88+
my ( $cmd, $name ) = @_;
89+
my $module = "OpenBSD::Pkg\u$cmd";
90+
eval "require $module;";
91+
if ($@) {
92+
die $@;
93+
}
94+
exit( $module->parse_and_run($name) );
95+
}
96+
97+
for my $i (@l) {
98+
if ( $0 =~ m/\/?pkg_$i$/ ) {
99+
run( $i, "pkg_$i" );
100+
}
101+
}
102+
103+
if (@ARGV) {
104+
for my $i (@l) {
105+
$ARGV[0] = $a{ $ARGV[0] } if defined $a{ $ARGV[0] };
106+
if ( $ARGV[0] eq $i ) {
107+
shift;
108+
if ( $i eq "info" ) {
109+
110+
# Take a FULLPKGNAME and return DESCR_CONTENTS and COMMENT
111+
my $ssth = $dbh->prepare(
112+
q{
113+
SELECT
114+
COMMENT,
115+
DESCRIPTION
116+
FROM ports_fts
117+
WHERE
118+
FULLPKGNAME = ?;
119+
}
120+
);
121+
$ssth->bind_param( 1, join( " ", @ARGV ) );
122+
$ssth->execute();
123+
while ( my $row = $ssth->fetchrow_hashref ) {
124+
print "Comment:\n$row->{COMMENT}\n\n";
125+
print "Description:\n$row->{DESCRIPTION}\n";
126+
}
127+
exit();
128+
}
129+
if ( $i eq "search" ) {
130+
131+
# TODO: what would be a better UX for displaying this stuff?
132+
my $ssth = $dbh->prepare(
133+
q{
134+
SELECT
135+
FULLPKGNAME,
136+
FULLPKGPATH,
137+
COMMENT,
138+
DESCRIPTION,
139+
highlight(ports_fts, 1, '[', ']') AS COMMENT_MATCH,
140+
highlight(ports_fts, 2, '[', ']') AS DESCR_MATCH
141+
FROM ports_fts
142+
WHERE ports_fts MATCH ? ORDER BY rank;
143+
}
144+
);
145+
$ssth->bind_param( 1, join( " ", @ARGV ) );
146+
$ssth->execute();
147+
while ( my $row = $ssth->fetchrow_hashref ) {
148+
print "$row->{FULLPKGNAME}\n";
149+
}
150+
exit();
151+
}
152+
else {
153+
run( $i, "pkg $i" );
154+
}
155+
}
156+
}
157+
}
158+
159+
print STDERR "Usage: pkg [", join( "|", @l ), "] [args]\n";
160+
exit(1);

zpkg.fzf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
zpkg() {
2+
/usr/local/sbin/pkg search "$@" | \
3+
fzf --preview "/usr/local/sbin/pkg info {1}"
4+
}

0 commit comments

Comments
 (0)