]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
grepc, grepc.1: -x: Add option to edit file extension
authorAlejandro Colomar <alx.manpages@gmail.com>
Wed, 11 May 2022 17:51:46 +0000 (19:51 +0200)
committerAlejandro Colomar <alx@kernel.org>
Wed, 29 Oct 2025 20:28:57 +0000 (21:28 +0100)
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
bin/grepc
share/man/man1/grepc.1

index 3d78821dacc07910218cff2d063edb8e94d2d6c4..0bcc112227d833f46a9eeb81f5e63a9cfdb64f0e 100755 (executable)
--- a/bin/grepc
+++ b/bin/grepc
@@ -1,20 +1,27 @@
 #!/bin/sh
 
 
+# Defaults:
+ext='\.[ch]$';
+
+
 grepc_usage()
 {
-       echo "Usage: $0 [OPTION] IDENTIFIER";
+       echo "Usage: $0 [OPTION ...] IDENTIFIER";
 }
 
 
 grepc_parse_cmd()
 {
-       while getopts "h" opt; do
+       while getopts "hx:" opt; do
                case "$opt" in
                h)
                        grepc_usage;
                        exit 0;
                        ;;
+               x)
+                       ext="$OPTARG";
+                       ;;
                ?)
                        grepc_usage >&2;
                        exit 1;
@@ -36,7 +43,7 @@ grepc_find_files()
        files="$(mktemp -t 'grepc.XXXXXX')";
 
        find . -type f \
-       | grep -P '\.[ch]' \
+       | grep -P "$ext" \
        | xargs grep -lPI "$1\b" \
        >"$files";
 }
index 02fb715c293917cb4f2cbb4eca3b33bc821fd6b5..88502a5dfe79d84fa7938587983da92fd36d1b08 100644 (file)
@@ -3,7 +3,7 @@
 grepc \- find C declarations and definitions in source code
 .SH SYNOPSIS
 .B grepc
-.RI [ option ]
+.RI [ option " ...]"
 .I identifier
 .SH DESCRIPTION
 .MR grepc 1
@@ -18,6 +18,13 @@ so it can be used to find complex patterns.
 .TP
 .B \-h
 Output a help message and exit.
+.TP
+.BI \-x " extension"
+Restrict the search to files ending with
+.IR extension .
+It is interpreted as a PCRE pattern.
+Default:
+.RB \(dq \e.[ch]$ \(dq.
 .SH EXAMPLES
 .EX
 .RB \(ti/src/nginx/unit$ " grepc nxt_sprintf;"