show statistics on SIGQUIT
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 12 Sep 2019 16:56:15 +0000 (18:56 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Thu, 19 Sep 2019 12:42:31 +0000 (14:42 +0200)
Misuse this signal as it's the best suited on linux being usually bound to
ctrl-\.  The same behaviour can also be seen in at least ping from iputils.
GNU dd offers similar progress on SIGUSR1, but this cannot be bound by stty.

barcat

diff --git a/barcat b/barcat
index bdfde47398a22d678ef8e2b02bd01a2afd74193f..650e4060b1b30fd9c743d2f870c6998ade606578 100755 (executable)
--- a/barcat
+++ b/barcat
@@ -87,6 +87,7 @@ $opt{'value-length'} = 1 if $opt{unmodified};
 
 my (@lines, @values, @order);
 
+$SIG{QUIT} = \&show_stat;
 $SIG{ALRM} = sub {
        show_lines();
        alarm $opt{interval} if defined $opt{interval} and $opt{interval} > 0;
@@ -220,7 +221,7 @@ say '' if $opt{spark};
 }
 show_lines();
 
-if ($opt{stat}) {
+sub show_stat {
        if ($opt{hidemin} or $opt{hidemax}) {
                $opt{hidemin} ||= 1;
                $opt{hidemax} ||= @lines;
@@ -238,6 +239,7 @@ if ($opt{stat}) {
        }
        say '';
 }
+show_stat() if $opt{stat};
 
 __END__
 =encoding utf8