summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorAlejandro Colomar <alx.manpages@gmail.com>2022-05-11 19:51:46 +0200
committerAlejandro Colomar <alx.manpages@gmail.com>2022-05-11 21:19:38 +0200
commitf417552f109cff273293be848b79813ee60110b4 (patch)
treeb05ff5f851a7c3b2a60dbb3e4c995157588c9130 /bin
parent4c4f042196f907f42fd06612c7037716246ae5ae (diff)
grepc, grepc.1: -g: Add option to restrict search to files tracked by git
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
Diffstat (limited to 'bin')
-rwxr-xr-xbin/grepc12
1 files changed, 10 insertions, 2 deletions
diff --git a/bin/grepc b/bin/grepc
index 0bcc112..89cd84d 100755
--- 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";