diff --git a/G/G b/G/G index 0e6056f..69a1671 100755 --- a/G/G +++ b/G/G @@ -14,10 +14,30 @@ B [[grep options] string] [[grep options] string] ... =head1 DESCRIPTION -B is a short hand of writing: +B is a short hand of writing (search for single lines matching expressions): grep --option string | grep --option2 string2 +or with B<-g> (search full files matching expressions): + + find . -type f | xargs grep -l string1 | xargs grep -l string1 + +=head1 OPTIONS + +=over 4 + +=item B<-g> + +Search current subtree for files that match all expressions - but not +necessarily on the same line. + +=item I + +All B options. + +=back + + =head1 EXAMPLE Grep for lines with Foo but not Bar: @@ -27,7 +47,7 @@ Grep for lines with Foo but not Bar: =head1 AUTHOR -Copyright (C) 2017 Ole Tange, +Copyright (C) 2017-2018 Ole Tange, http://ole.tange.dk and Free Software Foundation, Inc. @@ -51,27 +71,41 @@ along with this program. If not, see . =head1 DEPENDENCIES -B uses B. +B uses B and B. =head1 SEE ALSO -B +B =cut my $i = 0; -while(@ARGV) { - $_ = shift; +for(@ARGV) { + if($_ eq "-g") { + # -g = recursive-and file grep + $opt::g ||= 1; + # -g not an option for grep + next; + } push @{$cmd[$i]}, $_; if(/^[^-]/) { - $i++ + $i++; } } -if(@cmd) { +if($opt::g and @cmd) { + my $a = shift @cmd; + my $run = 'find . -type f | parallel -kXq grep -l '.shell_quote(@$a); + if(@cmd) { + $run .= '|' . + join"|", map { 'xargs -d"\n" grep -l '. + join(" ", shell_quote(@$_)) } @cmd; + } + exec $run; +} elsif(@cmd) { exec join"|", map { "grep ".join(" ", shell_quote(@$_)) } @cmd; } else { exec 'cat';