From: Laslo Hunhold <dev@frign.de>
Date: Thu, 10 Aug 2017 20:22:39 +0000 (+0200)
Subject: Reduce -o | -n to -s
X-Git-Url: https://git.xinqibao.xyz/slstatus.git/commitdiff_plain/c9d47405f4ab3cf99d7d2116fbb7622c02a27e5e?hp=4d33c360141952f6071d19c34c0395ad2ff668a1

Reduce -o | -n to -s

What we really want is to either output to WM_NAME or stdout. If we want
just one single line, we do slstatus | head -n 1.
---

diff --git a/slstatus.1 b/slstatus.1
index d29f197..f9ef3ad 100644
--- a/slstatus.1
+++ b/slstatus.1
@@ -6,7 +6,7 @@
 .Nd suckless status monitor
 .Sh SYNOPSIS
 .Nm
-.Op Fl o | n
+.Op Fl s
 .Sh DESCRIPTION
 .Nm
 is a suckless status monitor for window managers that use WM_NAME (e.g. dwm) or
@@ -16,10 +16,8 @@ By default,
 outputs to WM_NAME.
 .Sh OPTIONS
 .Bl -tag -width Ds
-.It Fl n
-Write to stdout once and exit.
-.It Fl o
-Write to stdout continuously.
+.It Fl s
+Write to stdout instead of WM_NAME.
 .El
 .Sh CUSTOMIZATION
 .Nm
diff --git a/slstatus.c b/slstatus.c
index b31f21d..4b6770b 100644
--- a/slstatus.c
+++ b/slstatus.c
@@ -75,7 +75,6 @@ static void usage(void);
 char *argv0;
 static unsigned short int delay = 0;
 static unsigned short int done;
-static unsigned short int oflag, nflag;
 static Display *dpy;
 
 #include "config.h"
@@ -840,41 +839,34 @@ sighandler(const int signo)
 static void
 usage(void)
 {
-	fprintf(stderr, "usage: %s [-o | -n]\n", argv0);
+	fprintf(stderr, "usage: %s [-s]\n", argv0);
 	exit(1);
 }
 
 int
 main(int argc, char *argv[])
 {
-	unsigned short int i;
-	char status_string[MAXLEN];
-	char *element;
 	struct arg argument;
 	struct sigaction act;
-	size_t len;
+	size_t i, len;
+	int sflag = 0;
+	char status_string[MAXLEN];
+	char *element;
 
 	ARGBEGIN {
-		case 'o':
-			oflag = 1;
-			break;
-		case 'n':
-			nflag = 1;
+		case 's':
+			sflag = 1;
 			break;
 		default:
 			usage();
 	} ARGEND
 
-	if (oflag && nflag) {
-		usage();
-	}
-
 	memset(&act, 0, sizeof(act));
 	act.sa_handler = sighandler;
 	sigaction(SIGINT,  &act, 0);
 	sigaction(SIGTERM, &act, 0);
 
-	if (!oflag) {
+	if (!sflag) {
 		dpy = XOpenDisplay(NULL);
 	}
 
@@ -896,11 +888,8 @@ main(int argc, char *argv[])
 			}
 		}
 
-		if (oflag) {
-			printf("%s\n", status_string);
-		} else if (nflag) {
+		if (sflag) {
 			printf("%s\n", status_string);
-			done = 1;
 		} else {
 			XStoreName(dpy, DefaultRootWindow(dpy), status_string);
 			XSync(dpy, False);
@@ -915,7 +904,7 @@ main(int argc, char *argv[])
 		}
 	}
 
-	if (!oflag) {
+	if (!sflag) {
 		XStoreName(dpy, DefaultRootWindow(dpy), NULL);
 		XCloseDisplay(dpy);
 	}