diff options
author | Gianni Ceccarelli <gianni.ceccarelli@net-a-porter.com> | 2012-07-26 12:10:58 +0100 |
---|---|---|
committer | Gianni Ceccarelli <gianni.ceccarelli@net-a-porter.com> | 2012-07-26 12:10:58 +0100 |
commit | 2240f1a381e3cfdcb6878dc94a4f8c263842c5fe (patch) | |
tree | 88ad05587bb0588b6383660d4a383733e60957fc /git-logc | |
parent | Merge branch 'master' into dakkar (diff) | |
download | git-prompt-2240f1a381e3cfdcb6878dc94a4f8c263842c5fe.tar.gz git-prompt-2240f1a381e3cfdcb6878dc94a4f8c263842c5fe.tar.bz2 git-prompt-2240f1a381e3cfdcb6878dc94a4f8c263842c5fe.zip |
logc script
Diffstat (limited to 'git-logc')
-rwxr-xr-x | git-logc | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/git-logc b/git-logc new file mode 100755 index 0000000..a38a827 --- /dev/null +++ b/git-logc @@ -0,0 +1,67 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use 5.014; +use Term::ANSIColor ':constants'; + +my $tty=-t STDOUT; +$ENV{ANSI_COLORS_DISABLED}=1 unless $tty; + +sub parse_line { + my ($line) = @_; + + my ($graph,$hash,$decor,$date,$name,$subj) = split /\0/,$line; + return $graph unless defined $hash; + $decor =~ s{^\s+\(|\)$}{}g; + my @decors = split /, /,$decor; + return $graph,$hash,\@decors,$date,$name,$subj; +} + +sub class_decor { + my ($decor) = @_; + + my $colour=BRIGHT_BLUE; + if ($decor eq 'HEAD') { + $colour=BRIGHT_CYAN; + } + elsif ($decor =~ s{^refs/tags/}{tag: }) { + $colour=BRIGHT_YELLOW; + } + elsif ($decor =~ s{^refs/remotes/}{}) { + $colour=BRIGHT_RED; + } + elsif ($decor =~ s{^refs/heads/}{}) { + $colour=BRIGHT_GREEN; + } + return $colour,$decor; +} + +open my $fh,'-|','git','log',@ARGV,'--graph','--decorate=full','--pretty=format:%x00%h%x00%d%x00%ar%x00%aN%x00%s',($tty ? '--color=always' : ()); +my $out; +if ($tty) { + open $out,'|-','less'; + $SIG{PIPE}=sub{exit 0}; +} +else { + open $out,'>&',\*STDOUT; +} + +while (my $line = <$fh>) { + my ($graph,$hash,$decors,$date,$name,$subj) = parse_line($line); + if (not defined $hash) { + print $out $graph; + next; + } + + my $ret = $graph.YELLOW."$hash ".RESET; + + if (@$decors) { + $ret .= '('. join(', ',map { + my ($col,$str) = class_decor($_); + BOLD.$col.$str.RESET + } + @$decors).') ' + } + $ret .= RED."[$date]".RESET." ".GREEN."$name".RESET." $subj"; + print $out $ret; +} |