-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapplying
executable file
·66 lines (52 loc) · 1.21 KB
/
applying
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/perl -w
# Fri 22 Nov 21:26:50 GMT 2019
(my $email='ch%christianjaeger,ch')=~ tr/%,/@./;
# didn't / don't I have this already ?
use strict; use warnings FATAL => 'uninitialized';
$0=~ /(.*?)([^\/]+)\z/s or die "?";
my ($mydir, $myname)=($1,$2);
sub usage {
print STDERR map{"$_\n"} @_ if @_;
print "$myname cmd [args]
Split stdin (on lines by default), and call cmd with args and the
split parts as additional arguments.
Options:
-z split input on \\0
-s split on whitespace
(Christian Jaeger <$email>)
";
exit (@_ ? 1 : 0);
}
my ($opt_z, $opt_s);
while (@ARGV) {
if ($ARGV[0] eq "-z") {
$opt_z=1;
shift;
} elsif ($ARGV[0] eq "-s") {
$opt_s=1;
shift
} elsif ($ARGV[0]=~ /^--?h(elp)?$/) {
usage
} else {
last
}
}
usage unless @ARGV;
usage "both -s and -z given" if ($opt_s and $opt_z);
my @cmd= @ARGV;
my @moreargs= do {
if ($opt_z) {
local $/ = "\0";
<STDIN>
} elsif ($opt_s) {
local $/;
my $cnt= <STDIN>;
split /\s+/, $cnt
} else {
<STDIN>
}
};
exec(@cmd, @moreargs)
or exit 127;
#use Chj::ruse;
#use Chj::Backtrace; use Chj::repl; repl;