exigrep: use a pager if stdout is connected to a terminal
[exim.git] / src / src / exigrep.src
index b678c058472b897b3b44db4a0a436e8a970b5000..abc6f3a31323d1e7d2e7906ee704999818b4ca10 100644 (file)
@@ -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.