-my $cmd = "git log --all --graph --format='$format'";
-open my $fh, '-|', $cmd or die $!;
+my @cmd = ('git', 'log', '--graph', "--format=$format",
+ # use either given arguments or --all to list all commits
+ (scalar @ARGV) ? @ARGV : '--all');
+open my $fh, '-|', @cmd or die $!;
+
+my $pager = $ENV{PAGER};
+# Try to find an usable pager without searching $PATH.
+if (not defined $pager) {
+ foreach my $path (qw(/usr/bin/less /bin/less /usr/bin/more /bin/more)) {
+ next if not -x $path;
+
+ $pager = $path;
+ last;
+ }
+}
+# Use a pager if STDOUT is a terminal.
+if (-t STDOUT and defined $pager) {
+ open STDOUT, '|-', $pager or die $!;
+}