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.
=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>
@ -60,7 +62,7 @@ Grep for lines with Foo, bar but not baz. Ignore case for bar and baz:
=head1 AUTHOR
Copyright (C) 2017-2018 Ole Tange,
Copyright (C) 2017-2023 Ole Tange,
http://ole.tange.dk and Free Software Foundation, Inc.
@ -95,7 +97,7 @@ B<grep>
=cut
my $i = 0;
my $add_i = "";
my @add_X;
for(@ARGV) {
if($_ eq "-g") {
@ -104,21 +106,18 @@ for(@ARGV) {
# -g not an option for grep
next;
}
if($_ eq "--i") {
# --i = add ignore case to the rest
$opt::i ||= 1;
$add_i = "-i";
# --i not an option for grep
if($_ =~ /^--(.)$/) {
# --X = add -X to the rest
$opt::X ||= 1;
push @add_X, "-$1";
# --X not an option for grep
next;
}
if($add_i) { push @{$cmd[$i]}, $add_i; $add_i = ""; }
push @{$cmd[$i]}, $_;
if(/^[^-]/) {
# This is not an option
if(@add_X) { unshift @{$cmd[$i]}, @add_X; }
$i++;
if($opt::i) {
# If --i: add -i as option
$add_i = "-i";
}
}
}