Download raw body.
pkg_add: allow reading from standard input
I noticed that pkg_add is not able to read package names from standard
input, even though it is mentioned in pkg_add(1). The diff below adds
this functionality. The only issue I found when testing the diff below
is when interaction is required, e.g. to select a flavour: pkg_add
mupdf. The options are displayed, but the command doesn't pause to take
my input, and I'm not sure why. I'd be grateful for any feedback.
Index: usr.sbin/pkg_add/OpenBSD/PkgAdd.pm
===================================================================
RCS file: /cvs/src/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm,v
retrieving revision 1.150
diff -u -p -u -p -r1.150 PkgAdd.pm
--- usr.sbin/pkg_add/OpenBSD/PkgAdd.pm 2 Jan 2024 10:25:48 -0000 1.150
+++ usr.sbin/pkg_add/OpenBSD/PkgAdd.pm 30 Sep 2024 14:54:25 -0000
@@ -1219,11 +1219,17 @@ sub process_parameters($self, $state)
} else {
# actual names
- for my $pkgname (@ARGV) {
- next if $pkgname =~ m/^quirks\-\d/;
- push(@{$state->{setlist}},
- $state->updateset->$add_hints($pkgname));
- }
+ my @src;
+ if (@ARGV == 1 && $ARGV[0] eq '-') {
+ @src = split(/\s+/, join(" ", <STDIN>));
+ } else {
+ @src = @ARGV;
+ }
+ for my $pkgname (@src) {
+ next if $pkgname =~ m/^quirks\-\d/;
+ push(@{$state->{setlist}},
+ $state->updateset->$add_hints($pkgname));
+ }
}
}
pkg_add: allow reading from standard input