From 2f9d9096aac148a26254801014feaff057b64fa0 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 24 May 2019 13:30:51 -0700 Subject: grep: add --exclude-dir. Used quite a lot, especially with `--exclude-dir=.git`. --- toys/posix/grep.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'toys/posix/grep.c') diff --git a/toys/posix/grep.c b/toys/posix/grep.c index 5afe38ca..30a98190 100644 --- a/toys/posix/grep.c +++ b/toys/posix/grep.c @@ -1,4 +1,4 @@ -/* grep.c - print lines what match given regular expression +/* grep.c - show lines matching regular expressions * * Copyright 2013 CE Strake * @@ -10,7 +10,7 @@ * echo hello | grep -f parent) TT.tried++; if (!dirtree_notdotdot(new)) return 0; - if (S_ISDIR(new->st.st_mode)) return DIRTREE_RECURSE; + if (S_ISDIR(new->st.st_mode)) { + for (al = TT.exclude_dir; al; al = al->next) + if (!fnmatch(al->arg, new->name, 0)) return 0; + return DIRTREE_RECURSE; + } if (TT.S || TT.M) { - struct arg_list *al; - for (al = TT.S; al; al = al->next) if (!fnmatch(al->arg, new->name, 0)) return 0; -- cgit v1.2.3