-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathauto-run
executable file
·57 lines (42 loc) · 1.22 KB
/
auto-run
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
#!/usr/bin/env perl
my $copyright= <<'COPYRIGHT';
# Copyright 2023 by Christian Jaeger <ch@christianjaeger.ch>
# Published under the same terms as perl itself
COPYRIGHT
use strict;
use utf8;
use warnings;
use warnings FATAL => 'uninitialized';
use experimental 'signatures';
my ($email_full)= $copyright=~ / by ([^\n]*)/s;
my ($mydir, $myname);
BEGIN {
$0=~ /(.*?)([^\/]+)\z/s or die "?";
($mydir, $myname)=($1,$2);
}
use Chj::xperlfunc ":all";
use Chj::IO::Command;
#use FP::Show; use FP::Repl; use FP::Repl::Trap; #
sub usage {
print STDERR map{"$_\n"} @_ if @_;
print "$myname binary_file [ args .. ]
Watch the binary file and run it with the given args whenever it
changes. (If the given binary file path does not contain a slash, ./
is prepended.)
($email_full)
";
exit (@_ ? 1 : 0);
}
usage unless @ARGV;
usage if $ARGV[0] =~ /^--?h(elp)?$/;
my ($binary, @args) = @ARGV;
my $binary_path = ($binary=~ m{/}) ? $binary : "./$binary";
my $C = Chj::IO::Command->new_sender("C_", $binary_path, @args);
my $trampoline = $C->xcontent; chomp $trampoline;
$C->xxfinish;
xexec("watchfile-run",
"-a",
"-t",
$trampoline,
'^'.quotemeta(basename $binary_path).'$',
dirname($binary_path));