summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx.manpages@gmail.com>2022-05-22 00:51:30 +0200
committerAlejandro Colomar <alx.manpages@gmail.com>2022-05-22 00:52:04 +0200
commit2ea37f6ec888e1124f459c01bbf95abc80ff9606 (patch)
tree5dda55e9829c9d7b4573c948a66548eb90d77cd7
parent63ae25c45d900f47483cf29ec3ceb7be56e8c202 (diff)
grepc, grepc.1: Add -i flag as in grep(1)
Also, add some symmetry between ${iflag} and ${lflag}. Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
-rwxr-xr-xbin/grepc20
-rw-r--r--share/man/man1/grepc.14
2 files changed, 16 insertions, 8 deletions
diff --git a/bin/grepc b/bin/grepc
index 7bfbadf..9c59c3d 100755
--- a/bin/grepc
+++ b/bin/grepc
@@ -5,6 +5,7 @@
git='no';
ext='\.[ch]$';
FILES='.';
+iflag='';
lflag='';
kflag='no';
tflag='no';
@@ -32,7 +33,7 @@ grepc_usage()
grepc_parse_cmd()
{
- while getopts "ghklt:x:" opt; do
+ while getopts "ghiklt:x:" opt; do
case "$opt" in
g)
git='yes';
@@ -41,11 +42,14 @@ grepc_parse_cmd()
grepc_usage;
exit 0;
;;
+ i)
+ iflag='i';
+ ;;
k)
kflag='yes';
;;
l)
- lflag='-l';
+ lflag='l';
kflag='yes';
;;
t)
@@ -131,16 +135,16 @@ grepc_find_files()
find $FILES -type f;
fi \
| grep -P -- "$ext" \
- | xargs grep -lPI -- "$1\b";
+ | xargs grep -${iflag}lPI -- "$1\b";
}
grepc_helper()
{
- xargs grep -lPI -- "$1" \
- | xargs grep -lP -- "$2" \
+ xargs grep -${iflag}lPI -- "$1" \
+ | xargs grep -${iflag}lP -- "$2" \
| sort \
- | xargs pcregrep $lflag -Mn -- "$3" /dev/null \
+ | xargs pcregrep -${iflag}${lflag}Mn -- "$3" /dev/null \
| if [ "$kflag" = 'no' ]; then
sed -E 's/^[^: ]+:[0-9]+:/\n\n&\n/';
else
@@ -285,8 +289,8 @@ grepc_type_typedef_struct_union_enum()
grepc_type_typedef_underlying_struct_union_enum()
{
- xargs grep -hP "^\s*typedef\s+(struct|union|enum)\s+.*\b$1;" <"$files" \
- | sed -E -e 's/^\s*typedef\s+//' -e "s/\s*\**\b$1;.*//" \
+ xargs grep -${iflag}hP "^\s*typedef\s+(struct|union|enum)\s+.*\b$1;" <"$files" \
+ | sed -E -e 's/^\s*typedef\s+//' -e "s/\s*\**\b$1;.*//${iflag}" \
| sed -E -e 's/^struct\s+//' -e 's/^union\s+//' -e 's/^enum\s+//' \
| while read -r t; do
test "$1" != "$t" \
diff --git a/share/man/man1/grepc.1 b/share/man/man1/grepc.1
index 9508f68..8a74fc8 100644
--- a/share/man/man1/grepc.1
+++ b/share/man/man1/grepc.1
@@ -114,6 +114,10 @@ Restrict the search to files tracked by git.
.B \-h
Output a help message and exit.
.TP
+.B \-i
+Ignore case distinctions in
+.IR pattern .
+.TP
.B \-k
Compact (kurz) output.
Don't print extra newlines