X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=tig.pl;h=d7272a3183981ad8040d2c963f9f6fe1a4e03bf5;hb=cf2f4142baba6dc0bcc9d8af37e83cb8ca3add0e;hp=5fc7625ea46ff91162aab61c897dc3fdc06790f3;hpb=038da645d825eb46018d0e92317594e54b37250e;p=config%2Fdotfiles.git diff --git a/tig.pl b/tig.pl index 5fc7625..d7272a3 100755 --- a/tig.pl +++ b/tig.pl @@ -40,8 +40,25 @@ my $format = '%x00' # separator from --graph . '%an' . '%x00' # author name . '%s' . '%x00' # subject . '%d'; # ref names -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 $!; +} while (my $line = <$fh>) { # History graph line. @@ -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 $!; +}