added option to output only once and exit afterwards

This commit is contained in:
Aaron Marcher 2017-05-11 19:06:45 +02:00
parent ac1a57ec30
commit 870d68d44e
No known key found for this signature in database
GPG Key ID: 74B048E5C2474F9A
2 changed files with 16 additions and 7 deletions

View File

@ -15,7 +15,10 @@ run slstatus as daemon in background
display help display help
.TP .TP
.B \-o .B \-o
output to console instead of WM_NAME output continuously to console instead of WM_NAME
.TP
.B \-n
output to console once and exit
.TP .TP
.B \-v .B \-v
display version and copyright details display version and copyright details

View File

@ -71,7 +71,7 @@ static void usage(const int eval);
char *argv0; char *argv0;
static unsigned short int delay = 0; static unsigned short int delay = 0;
static unsigned short int done; static unsigned short int done;
static unsigned short int dflag, oflag; static unsigned short int dflag, oflag, nflag;
static Display *dpy; static Display *dpy;
#include "config.h" #include "config.h"
@ -775,7 +775,7 @@ sighandler(const int signo)
static void static void
usage(const int eval) 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); exit(eval);
} }
@ -795,6 +795,9 @@ main(int argc, char *argv[])
case 'o': case 'o':
oflag = 1; oflag = 1;
break; break;
case 'n':
nflag = 1;
break;
case 'v': case 'v':
printf("slstatus (C) 2016-2017 slstatus engineers\n"); printf("slstatus (C) 2016-2017 slstatus engineers\n");
return 0; return 0;
@ -804,7 +807,7 @@ main(int argc, char *argv[])
usage(1); usage(1);
} ARGEND } ARGEND
if (dflag && oflag) { if ((dflag && oflag) || (dflag && nflag) || (oflag && nflag)) {
usage(1); usage(1);
} }
if (dflag && daemon(1, 1) < 0) { if (dflag && daemon(1, 1) < 0) {
@ -842,11 +845,14 @@ main(int argc, char *argv[])
free(element); 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); XStoreName(dpy, DefaultRootWindow(dpy), status_string);
XSync(dpy, False); XSync(dpy, False);
} else {
printf("%s\n", status_string);
} }
if ((UPDATE_INTERVAL - delay) <= 0) { if ((UPDATE_INTERVAL - delay) <= 0) {