From: Mischa POSLAWSKY Date: Thu, 3 Feb 2011 23:09:39 +0000 (+0100) Subject: sample options (original line(s), unique threshold) X-Git-Url: http://git.shiar.nl/git-grep-footer.git/commitdiff_plain/511a2ca1ce6002f6f133d3b681993bba390d77df sample options (original line(s), unique threshold) --- diff --git a/git-grep-footer b/git-grep-footer index bc71345..906ae92 100755 --- a/git-grep-footer +++ b/git-grep-footer @@ -10,8 +10,9 @@ 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; @@ -53,6 +54,8 @@ while (readline) { next LINE; }; + push @header, $_ if defined $opt{max}; + given ($opt{simplify} // 'no') { when ('strict') { $header[1] =~ s{ @@ -64,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 @@ -74,7 +77,7 @@ while (readline) { } } when (['all', 'any']) { - pop @header; + $header[1] = undef; } when ('no') { } @@ -84,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; } @@ -97,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;