From 870d68d44e33f9fb7a5402becbc0b5c363066bcc Mon Sep 17 00:00:00 2001 From: Aaron Marcher Date: Thu, 11 May 2017 19:06:45 +0200 Subject: added option to output only once and exit afterwards --- slstatus.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'slstatus.c') diff --git a/slstatus.c b/slstatus.c index 9e6aca0..8241451 100644 --- a/slstatus.c +++ b/slstatus.c @@ -71,7 +71,7 @@ static void usage(const int eval); char *argv0; static unsigned short int delay = 0; static unsigned short int done; -static unsigned short int dflag, oflag; +static unsigned short int dflag, oflag, nflag; static Display *dpy; #include "config.h" @@ -775,7 +775,7 @@ sighandler(const int signo) static void usage(const int eval) { - fprintf(stderr, "usage: %s [-d] [-o] [-v] [-h]\n", argv0); + fprintf(stderr, "usage: %s [-d] [-o] [-n] [-v] [-h]\n", argv0); exit(eval); } @@ -795,6 +795,9 @@ main(int argc, char *argv[]) case 'o': oflag = 1; break; + case 'n': + nflag = 1; + break; case 'v': printf("slstatus (C) 2016-2017 slstatus engineers\n"); return 0; @@ -804,7 +807,7 @@ main(int argc, char *argv[]) usage(1); } ARGEND - if (dflag && oflag) { + if ((dflag && oflag) || (dflag && nflag) || (oflag && nflag)) { usage(1); } if (dflag && daemon(1, 1) < 0) { @@ -842,11 +845,14 @@ main(int argc, char *argv[]) free(element); } - if (!oflag) { + if (oflag) { + printf("%s\n", status_string); + } else if (nflag) { + printf("%s\n", status_string); + done = 1; + } else { XStoreName(dpy, DefaultRootWindow(dpy), status_string); XSync(dpy, False); - } else { - printf("%s\n", status_string); } if ((UPDATE_INTERVAL - delay) <= 0) { -- cgit v1.2.3