diff options
author | Alejandro Colomar <alx.manpages@gmail.com> | 2022-05-11 20:46:01 +0200 |
---|---|---|
committer | Alejandro Colomar <alx.manpages@gmail.com> | 2022-05-11 21:24:44 +0200 |
commit | 439553e50dbc17c9ef29a50aaeae93bb9f6cbf81 (patch) | |
tree | 83685a6788d963b107d652c846046f7570252e97 /bin | |
parent | f417552f109cff273293be848b79813ee60110b4 (diff) |
grepc, grepc.1: Add optional FILE trailing arguments
Reported-by: наб <nabijaczleweli@nabijaczleweli.xyz>
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/grepc | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -4,11 +4,12 @@ # Defaults: git='no'; ext='\.[ch]$'; +FILES='.'; grepc_usage() { - echo "Usage: $0 [OPTION ...] IDENTIFIER"; + echo "Usage: $0 [OPTION ...] IDENTIFIER [FILE ...]"; } @@ -34,11 +35,16 @@ grepc_parse_cmd() done; shift $(($OPTIND-1)); - if [ $# -ne 1 ]; then + if [ $# -lt 1 ]; then grepc_usage >&2; exit 1; fi; identifier=$1; + shift; + + if [ $# -gt 0 ]; then + FILES=$@; + fi; } @@ -47,9 +53,9 @@ grepc_find_files() files="$(mktemp -t 'grepc.XXXXXX')"; if [ "$git" = 'yes' ]; then - git ls-files .; + git ls-files $FILES; else - find . -type f; + find $FILES -type f; fi \ | grep -P "$ext" \ | xargs grep -lPI "$1\b" \ |