G: Implemented --X = -X for all following args.

This commit is contained in:
Ole Tange 2023-01-25 23:48:25 +01:00
parent d9d02d7137
commit f1cdc457fd

27
G/G
View file

@ -34,9 +34,11 @@ necessarily on the same line.
If a parent dir contains a B<.git> dir B<git grep> is used. If a parent dir contains a B<.git> dir B<git grep> is used.
=item B<--i> =item B<-->I<X>
Ignore case for all following options. Apply single letter option X to all following options.
E.g. B<--i> will prepend B<-i> to all following options.
=item I<other options> =item I<other options>
@ -60,7 +62,7 @@ Grep for lines with Foo, bar but not baz. Ignore case for bar and baz:
=head1 AUTHOR =head1 AUTHOR
Copyright (C) 2017-2018 Ole Tange, Copyright (C) 2017-2023 Ole Tange,
http://ole.tange.dk and Free Software Foundation, Inc. http://ole.tange.dk and Free Software Foundation, Inc.
@ -95,7 +97,7 @@ B<grep>
=cut =cut
my $i = 0; my $i = 0;
my $add_i = ""; my @add_X;
for(@ARGV) { for(@ARGV) {
if($_ eq "-g") { if($_ eq "-g") {
@ -104,21 +106,18 @@ for(@ARGV) {
# -g not an option for grep # -g not an option for grep
next; next;
} }
if($_ eq "--i") { if($_ =~ /^--(.)$/) {
# --i = add ignore case to the rest # --X = add -X to the rest
$opt::i ||= 1; $opt::X ||= 1;
$add_i = "-i"; push @add_X, "-$1";
# --i not an option for grep # --X not an option for grep
next; next;
} }
if($add_i) { push @{$cmd[$i]}, $add_i; $add_i = ""; }
push @{$cmd[$i]}, $_; push @{$cmd[$i]}, $_;
if(/^[^-]/) { if(/^[^-]/) {
# This is not an option
if(@add_X) { unshift @{$cmd[$i]}, @add_X; }
$i++; $i++;
if($opt::i) {
# If --i: add -i as option
$add_i = "-i";
}
} }
} }