X-Git-Url: http://git.shiar.net/git-grep-footer.git/blobdiff_plain/859f2414c9f4b8533dcd3e6c1661f10031081630..511a2ca1ce6002f6f133d3b681993bba390d77df:/git-grep-footer diff --git a/git-grep-footer b/git-grep-footer index dcb24d4..906ae92 100755 --- a/git-grep-footer +++ b/git-grep-footer @@ -1,7 +1,8 @@ -#!/usr/bin/perl -0 -CO +#!/usr/bin/perl use 5.010; use strict; use warnings; +use open ':std', OUT => ':utf8'; use Encode 'decode'; use Data::Dump 'pp'; use Getopt::Long; @@ -9,11 +10,13 @@ use Getopt::Long; GetOptions(\my %opt, 'debug!', 'simplify|s:s', - 'unique|u!', 'ignore-case|i!', + 'min|min-count|unique|u:i', + 'max|max-count|show|n:i', ) or die; local $| = 1; +local $/ = "\0"; my $HEADERMATCH = qr/ [a-z]+ (?: (?:-\w+)+ | \ by ) /ix; @@ -51,6 +54,8 @@ while (readline) { next LINE; }; + push @header, $_ if defined $opt{max}; + given ($opt{simplify} // 'no') { when ('strict') { $header[1] =~ s{ @@ -62,7 +67,7 @@ while (readline) { } when (['text', '']) { when ($header[0] =~ /[ _-] (?: by | to ) $/imsx) { - pop @header; + $header[1] = undef; } for ($header[1]) { s{\b (https?)://\S+ }{[$1]}gmsx; # url @@ -72,7 +77,7 @@ while (readline) { } } when (['all', 'any']) { - pop @header; + $header[1] = undef; } when ('no') { } @@ -82,9 +87,11 @@ while (readline) { } if ($opt{'ignore-case'}) { - $_ = lc for @header; + $_ = lc for $header[0], $header[1] // (); } + pop @header if not defined $header[-1]; + push @headers, \@header; } @@ -95,11 +102,13 @@ while (readline) { } for (@headers) { - if ($opt{unique}) { + if (defined $opt{min} or $opt{max}) { state $seen; - next if $seen->{ $_->[0] }->{ $_->[1] // '' }++; + my $count = $seen->{ $_->[0] }->{ $_->[1] // '' }++; + next if $count >= ($opt{min} // 0) + ($opt{max} || 1); + next if $count < ($opt{min} // 0); } - say join ': ', @$_; + say $_->[2] // join(': ', @$_); } last BLOCK;