]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
grepc, grepc.1: -g: Add option to restrict search to files tracked by git
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 0bcc112227d833f46a9eeb81f5e63a9cfdb64f0e..89cd84d11b45d6b39de2dd22ff8960fff7a76936 100755 (executable)
--- a/bin/grepc
+++ b/bin/grepc
@@ -2,6 +2,7 @@
 
 
 # Defaults:
+git='no';
 ext='\.[ch]$';
 
 
@@ -13,8 +14,11 @@ grepc_usage()
 
 grepc_parse_cmd()
 {
-       while getopts "hx:" opt; do
+       while getopts "ghx:" opt; do
                case "$opt" in
+               g)
+                       git='yes';
+                       ;;
                h)
                        grepc_usage;
                        exit 0;
@@ -42,7 +46,11 @@ grepc_find_files()
 {
        files="$(mktemp -t 'grepc.XXXXXX')";
 
-       find . -type f \
+       if [ "$git" = 'yes' ]; then
+               git ls-files .;
+       else
+               find . -type f;
+       fi \
        | grep -P "$ext" \
        | xargs grep -lPI "$1\b" \
        >"$files";
index 88502a5dfe79d84fa7938587983da92fd36d1b08..6caaeb5044ac4b0ff2327179e602d9dff55761cf 100644 (file)
@@ -16,6 +16,9 @@ but it is actually a PCRE pattern,
 so it can be used to find complex patterns.
 .SH OPTIONS
 .TP
+.B \-g
+Restrict the search to files tracked by git.
+.TP
 .B \-h
 Output a help message and exit.
 .TP
@@ -57,6 +60,7 @@ Originally written by
 Alejandro Colomar
 .ME .
 .SH SEE ALSO
+.MR git-ls-files 1 ,
 .MR pcregrep 1 ,
 .MR pcresyntax 3 ,
 .MR pcrepattern 3