X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=tig.pl;h=d7272a3183981ad8040d2c963f9f6fe1a4e03bf5;hb=cf2f4142baba6dc0bcc9d8af37e83cb8ca3add0e;hp=3939deb1f5f25bfed13b957fc3fcd43caa6eb2ac;hpb=6629b8c8e9ee16178a5f2fa464936e35a9e58d24;p=config%2Fdotfiles.git diff --git a/tig.pl b/tig.pl index 3939deb..d7272a3 100755 --- a/tig.pl +++ b/tig.pl @@ -40,9 +40,26 @@ my $format = '%x00' # separator from --graph . '%an' . '%x00' # author name . '%s' . '%x00' # subject . '%d'; # ref names -my @cmd = ('git', 'log', '--all', '--graph', "--format=$format"); +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 $!; +} + while (my $line = <$fh>) { # History graph line. if ($line =~ m{^([|/\\_ ]+)$}) { @@ -51,7 +68,7 @@ while (my $line = <$fh>) { } # Commit line. - $line =~ /^([ *|.-]+)\x00(.+)\x00(.+)\x00(.+)\x00(.+)\x00(.*)$/ + $line =~ /^([ *|.\\-]+)\x00(.+)\x00(.+)\x00(.+)\x00(.*)\x00(.*)$/ or die $line; my $prefix = $1; my $hash = colored($2, $color_hash); @@ -94,3 +111,9 @@ while (my $line = <$fh>) { } close $fh or die $!; + +# Necessary for the redirection to a pager or the pager terminates after our +# script finishes without displaying all data. +if (defined $pager) { + close STDOUT or die $!; +}