X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=tig.pl;h=5fc7625ea46ff91162aab61c897dc3fdc06790f3;hb=038da645d825eb46018d0e92317594e54b37250e;hp=615107a993b2d8437cc2ef29bddec31e9955d402;hpb=e4c16ff97afe69adec52cbbf4b4d66455d4a3371;p=config%2Fdotfiles.git diff --git a/tig.pl b/tig.pl index 615107a..5fc7625 100755 --- a/tig.pl +++ b/tig.pl @@ -34,7 +34,8 @@ my $color_ref_reference = 'red bold'; my $color_author = 'magenta'; -my $format = '%h' . '%x00' # abbreviated commit hash +my $format = '%x00' # separator from --graph + . '%h' . '%x00' # abbreviated commit hash . '%at' . '%x00' # author date . '%an' . '%x00' # author name . '%s' . '%x00' # subject @@ -44,13 +45,14 @@ open my $fh, '-|', $cmd or die $!; while (my $line = <$fh>) { # History graph line. - if ($line =~ m{^([|/\\ ]+)$}) { + if ($line =~ m{^([|/\\_ ]+)$}) { print colored($line, $color_graph); next; } # Commit line. - $line =~ /^([ *|]+) (.+)\x00(.+)\x00(.+)\x00(.+)\x00(.*)$/ or die; + $line =~ /^([ *|]+)\x00(.+)\x00(.+)\x00(.+)\x00(.+)\x00(.*)$/ + or die $line; my $prefix = $1; my $hash = colored($2, $color_hash); my $date = POSIX::strftime('%Y-%m-%d', localtime($3)); @@ -58,14 +60,37 @@ while (my $line = <$fh>) { my $message = $5; my $refs = $6; + # Strip trailing whitespace. + $prefix =~ s/\s+$//; # Color "graph". $prefix =~ s/\|/colored($&, $color_graph)/ge; - # Strip leading whitespace. + # Strip leading whitespace and braces. $refs =~ s/^\s+//; + $refs =~ tr/()//d; - printf "%s %s %s %s %s %s\n", - $prefix, $hash, $date, $author, $message, $refs; + # Color refs. + $refs = join colored(', ', $color_ref_sep), map { + my $color; + if ($_ eq 'HEAD') { + $color = $color_ref_head; + } elsif (m{/}) { + $color = $color_ref_reference; + } else { + $color = $color_ref_branch; + } + colored($_, $color); + } split /, /, $refs; + + if ($refs ne '') { + $refs = ' ' + . colored('(', $color_ref_sep) + . $refs + . colored(')', $color_ref_sep); + } + + printf "%s %s %s %s%s %s\n", + $prefix, $hash, $date, $author, $refs, $message; } close $fh or die $!;