summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>2017-03-19 01:12:38 +0100
committerHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>2017-03-19 01:13:09 +0100
commitab13201f8a5517a379c461767f16feafa8e01ffb (patch)
tree7743a8ecbae369ecc4d89fdc1fa977f2d812e29d
parente236f915d39e27c89ac6e9ef8dd6bdf38f164a6b (diff)
exigrep: use a pager if stdout is connected to a terminal
-rw-r--r--src/src/exigrep.src10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/src/exigrep.src b/src/src/exigrep.src
index b678c0584..abc6f3a31 100644
--- a/src/src/exigrep.src
+++ b/src/src/exigrep.src
@@ -220,6 +220,16 @@ pod2usage if not @ARGV;
$pattern = shift @ARGV;
$pattern = quotemeta $pattern if $args{l};
+# Start a pager if output goes to a terminal
+if (-t 1)
+ {
+ foreach ($ENV{PAGER}//(), 'less', 'more')
+ {
+ open(my $pager, '|-', $_) or next;
+ select $pager;
+ last;
+ }
+}
# If file arguments are given, open each one and process according as it is
# is compressed or not.