diff options
author | Christian Hesse <mail@eworm.de> | 2014-07-21 12:45:55 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2014-07-21 12:45:55 +0200 |
commit | d5f62e3a36ac094f4063da42a653c51d7003ac47 (patch) | |
tree | 9eb4f1aa67f164cfb291308dfa2019564dc2e233 | |
parent | a27eba09c69b48f3f3c6a6ce08fa0ef5c1a37472 (diff) | |
download | journal-notify-d5f62e3a36ac094f4063da42a653c51d7003ac47.tar.gz journal-notify-d5f62e3a36ac094f4063da42a653c51d7003ac47.tar.zst |
allow to add logical AND and OR to matches
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | journal-notify.c | 24 |
2 files changed, 24 insertions, 2 deletions
@@ -50,12 +50,14 @@ Be warned: This can flood your disktop with notifications. `journal-notify` accepts some options: +* *-a*: combine matches with a logical AND * *-e*: use extended regular expressions * *-h*: show help * *-i ICON*: icon to use * *-m MATCH*: This can be specified more than once. The option accepts matches to systemd journal fields. (see `man 7 systemd.journal-fields`) * *-n*: no case sensitive regular expressions +* *-o*: combine matches with a logical OR * *-r REGEX*: This add a regular expression match for the message field. * *-v* verbose output, can be specified multiple times diff --git a/journal-notify.c b/journal-notify.c index 0f54090..bc7740c 100644 --- a/journal-notify.c +++ b/journal-notify.c @@ -18,7 +18,7 @@ const char * program = NULL; -#define OPTSTRING "ehi:m:nr:v" +#define OPTSTRING "aehi:m:nor:v" #define DEFAULTICON "dialog-information" int notify(const char * summary, const char * body, const char * icon) { @@ -71,7 +71,7 @@ int main(int argc, char **argv) { regex_flags |= REG_EXTENDED; break; case 'h': - fprintf(stderr, "usage: %s [-e] [-h] [-i ICON] [-m MATCH] [-n] [-r REGEX] [-vv]\n", program); + fprintf(stderr, "usage: %s [-e] [-h] [-i ICON] [-m MATCH] [-o -m MATCH] [-a -m MATCH] [-n] [-r REGEX] [-vv]\n", program); return EXIT_SUCCESS; case 'n': regex_flags |= REG_ICASE; @@ -98,6 +98,16 @@ int main(int argc, char **argv) { /* get command line options - part II*/ while ((i = getopt(argc, argv, OPTSTRING)) != -1) { switch (i) { + case 'a': + if (verbose > 1) + printf("Adding logical AND to match...\n"); + + if ((rc = sd_journal_add_conjunction(journal)) < 0) { + fprintf(stderr, "Failed to add logical AND to match.\n"); + goto out20; + } + + break; case 'i': icon = optarg; break; @@ -111,6 +121,16 @@ int main(int argc, char **argv) { } break; + case 'o': + if (verbose > 1) + printf("Adding logical OR to match...\n"); + + if ((rc = sd_journal_add_disjunction(journal)) < 0) { + fprintf(stderr, "Failed to add logical OR to match.\n"); + goto out20; + } + + break; case 'r': if (verbose > 1) printf("Adding regular expression '%s'...\n", optarg); |