diff options
author | Alejandro Colomar <alx@kernel.org> | 2023-11-03 22:21:30 +0100 |
---|---|---|
committer | Alejandro Colomar <alx@kernel.org> | 2023-11-03 23:23:28 +0100 |
commit | 518f28157358862ddda3bc94e546447b81e8936f (patch) | |
tree | 771a38ffaa255d68d5257dacae94ceed4d0af5c3 /bin | |
parent | d34c191fce67f9f22b974c6db9a6ef14f5479d79 (diff) |
Add recursive search back in with -r
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/grepc | 24 |
1 files changed, 22 insertions, 2 deletions
@@ -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 |