aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-01-28 22:17:34 +0100
committerThomas Voss <mail@thomasvoss.com> 2024-01-28 22:17:34 +0100
commit1647177908a654f41234e4c457fd17cf4e61d926 (patch)
tree23699b9331b2dbd37587caa25d0537f85ea8f263
parent3202be9ceac81d8e10e432ffbfea774f6240788b (diff)
Exit with EXIT_FAILURE if we got no matches
-rw-r--r--src/grab.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/grab.c b/src/grab.c
index f262451..97c77ef 100644
--- a/src/grab.c
+++ b/src/grab.c
@@ -94,6 +94,7 @@ static int svposcmp(const void *, const void *);
static char *env_or_default(const char *, const char *);
static int filecnt, rv;
+static bool got_match;
static bool bflag, cflag, nflag, iflag, sflag, Uflag, zflag;
static bool fflag = GIT_GRAB;
static put_func *putf;
@@ -260,7 +261,7 @@ main(int argc, char **argv)
free(ops.buf);
#endif
- return rv;
+ return got_match ? rv : EXIT_FAILURE;
}
struct ops
@@ -593,6 +594,8 @@ putm(struct sv sv, struct matches *ms, const char *filename)
struct matches valid;
static const char *fn, *hl, *ln, *se;
+ got_match = true;
+
if (cflag && !fn) {
char *optstr;
if ((optstr = env_or_default("GRAB_COLORS", nullptr))) {
@@ -743,6 +746,8 @@ putm_nc(struct sv sv, struct matches *ms, const char *filename)
{
(void)ms;
+ got_match = true;
+
if (fflag || filecnt > 1) {
char sep = zflag ? '\0' : ':';
printf("%s%c", filename, sep);