]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
Add recursive search back in with -r
authorAlejandro Colomar <alx@kernel.org>
Fri, 3 Nov 2023 21:21:30 +0000 (22:21 +0100)
committerAlejandro Colomar <alx@kernel.org>
Wed, 29 Oct 2025 20:29:18 +0000 (21:29 +0100)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
bin/grepc
share/man/man1/grepc.1

index db053d98e27ef4163d96e1e25ada1810dd158dab..6d05b25a44fe7b99f6382724092a16ace73524ad 100755 (executable)
--- a/bin/grepc
+++ b/bin/grepc
@@ -5,6 +5,7 @@
 iflag='';
 lflag='';
 kflag='no';
+rflag='no';
 tflag='no';
 t_e='no';
 t_fp='no';
@@ -38,7 +39,7 @@ grepc_err()
 
 grepc_parse_cmd()
 {
-       while getopts "chiklt:" opt; do
+       while getopts "chiklrt:" opt; do
                case "$opt" in
                c)
                        cflag='yes';
@@ -57,6 +58,9 @@ grepc_parse_cmd()
                        lflag='l';
                        kflag='yes';
                        ;;
+               r)
+                       rflag='yes';
+                       ;;
                t)
                        case "$OPTARG" in
                        e)
@@ -228,11 +232,27 @@ grepc_patterns()
 }
 
 
+grepc_search()
+{
+       p="$(mktemp -u -t grepc.p.XXXXXX)";
+
+       grepc_patterns "$identifier" >"$p";
+
+       if test "$rflag" = 'no'; then
+               pcre2grep -${iflag}${lflag}HMn -f "$p" $files;
+       else
+               find $files -type f \
+               | xargs grep -${iflag}lPI -- "$identifier" \
+               | xargs pcre2grep -${iflag}${lflag}HMn -f "$p";
+       fi;
+}
+
+
 main()
 {
        grepc_parse_cmd "$@" </dev/null;
 
-       pcre2grep -${iflag}${lflag}HMn -f <(grepc_patterns "$identifier") $files \
+       grepc_search \
        | sed -E -f <(test "$kflag" = 'no'  && echo 's/^[^: ]+:[0-9]+:/\n\n&\n/') \
        | perl -pe "$(test "$cflag" = 'yes' && echo 's/('"$identifier"')/\033[32m\1\033[0m/' || echo 's///')" \
        | if [ -n "$lflag" ]; then
index 87850204dcbb733300e36b9b36f24f1e3c1b6e8e..eb79522055a4a3b00322ac4815e11573398b657b 100644 (file)
@@ -21,7 +21,8 @@ and word boundaries are implicitly added to it in most cases.
 If no
 .I file
 is given,
-the program reads the standard input.
+nonrecursive searches read standard input,
+and recursive searches examine the working directory.
 .SS Types of code
 This program can search for several types of code.
 The following arguments can be passed to the
@@ -143,6 +144,14 @@ instead print the name of each input file
 from which output would normally have been printed.
 Each file is only printed once.
 .TP
+.B \-r
+Recursive search.
+If an input file is a directory,
+read all files under such directory, recursively,
+without following symbolic links.
+This is useful even if specific files are specified in the command line
+as it enables certain optimizations that cannot be enabled in filter mode.
+.TP
 .BI \-t " type"
 Restrict the search to a specific
 .I type