diff options
author | Alejandro Colomar <alx@kernel.org> | 2023-11-05 16:29:23 +0100 |
---|---|---|
committer | Alejandro Colomar <alx@kernel.org> | 2023-11-05 17:41:12 +0100 |
commit | 92cea19cf909f70b35c2e888985ff574c312e15f (patch) | |
tree | ab559b2edd78dcc5e4ea04a7dadb9a8424279b57 | |
parent | 287df0407c9660ac60ca8e124a0fab61061b022d (diff) |
bin/grepc: srcfix (Remove grepc_search() and main())
Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rwxr-xr-x | bin/grepc | 72 |
1 files changed, 29 insertions, 43 deletions
@@ -105,8 +105,6 @@ test $# -lt 1 && grepc_err "Missing identifier."; identifier=$1; shift; -files=$*; - if [ "$t" = 'no' ]; then t_e='yes'; t_fp='yes'; @@ -177,46 +175,34 @@ patterns="$(mktemp -t grepc.patterns.XXXXXX)"; ) >"$patterns"; -grepc_search() -{ - local opts=''; - - opts="$opts $A"; - opts="$opts $B"; - opts="$opts $C"; - opts="$opts $c"; - opts="$opts $h"; - opts="$opts $i"; - opts="$opts $l"; - opts="$opts -M"; - opts="$opts $n"; - - if test -z "$files"; then - pcre2grep $opts -f "$patterns"; - else - find $files -type f \ - | if test -z "$c"; then - xargs grep -${i}lPI -- "$identifier"; - else - cat; - fi \ - | xargs pcre2grep $opts -f "$patterns"; - fi; -} - - -main() -{ - grepc_search \ - | sed -E -f <(test "$k" = 'no' && echo 's/^[^: ]+:[0-9]+:/\n\n&\n/') \ - | perl -pe "$(test "$r" = 'yes' && echo 's/('"$identifier"')/\033[32m\1\033[0m/' || echo 's///')" \ - | if [ -n "$l" ]; then - sort \ - | uniq; +opts=''; +opts="$opts $A"; +opts="$opts $B"; +opts="$opts $C"; +opts="$opts $c"; +opts="$opts $h"; +opts="$opts $i"; +opts="$opts $l"; +opts="$opts -M"; +opts="$opts $n"; + + +if test -z "$*"; then + pcre2grep $opts -f "$patterns"; +else + find "$@" -type f \ + | if test -z "$c"; then + xargs grep -${i}lPI -- "$identifier"; else cat; - fi; -} - - -main; + fi \ + | xargs pcre2grep $opts -f "$patterns"; +fi \ +| sed -E -f <(test "$k" = 'no' && echo 's/^[^: ]+:[0-9]+:/\n\n&\n/') \ +| perl -pe "$(test "$r" = 'yes' && echo 's/('"$identifier"')/\033[32m\1\033[0m/' || echo 's///')" \ +| if [ -n "$l" ]; then + sort \ + | uniq; +else + cat; +fi; |