Add a -1 option flag
authorDaniel Moch <daniel@danielmoch.com>
Tue, 23 Jun 2020 20:35:43 +0000 (16:35 -0400)
committerAaron Marcher <me@drkhsh.at>
Mon, 30 Nov 2020 20:23:56 +0000 (21:23 +0100)
Allow slstatus to be used by programs that can grab status by calling
an external program on a periodic basis (e.g. tmux)

slstatus.1
slstatus.c

index da1a99a6b6ffeee037785ea4de80ad7fc5a1b07e..d802037355f6a05a2c565883c92c9aa65dc35f5f 100644 (file)
@@ -1,4 +1,4 @@
-.Dd 2017-08-10
+.Dd 2020-06-23
 .Dt SLSTATUS 1
 .Os
 .Sh NAME
@@ -7,6 +7,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl s
+.Op Fl 1
 .Sh DESCRIPTION
 .Nm
 is a suckless status monitor for window managers that use WM_NAME (e.g. dwm) or
@@ -18,6 +19,8 @@ outputs to WM_NAME.
 .Bl -tag -width Ds
 .It Fl s
 Write to stdout instead of WM_NAME.
+.It Fl 1
+Write once to stdout and quit.
 .El
 .Sh CUSTOMIZATION
 .Nm
index 0806773a7d1173cfa8bfbc0983d8e5a28743b399..64da5cb6aba41ae184ada5a631a190696987fed0 100644 (file)
@@ -41,7 +41,7 @@ difftimespec(struct timespec *res, struct timespec *a, struct timespec *b)
 static void
 usage(void)
 {
-       die("usage: %s [-s]", argv0);
+       die("usage: %s [-s] [-1]", argv0);
 }
 
 int
@@ -56,6 +56,9 @@ main(int argc, char *argv[])
 
        sflag = 0;
        ARGBEGIN {
+               case '1':
+                       done = 1;
+                       /* fallthrough */
                case 's':
                        sflag = 1;
                        break;
@@ -78,7 +81,7 @@ main(int argc, char *argv[])
                die("XOpenDisplay: Failed to open display");
        }
 
-       while (!done) {
+       do {
                if (clock_gettime(CLOCK_MONOTONIC, &start) < 0) {
                        die("clock_gettime:");
                }
@@ -125,7 +128,7 @@ main(int argc, char *argv[])
                                }
                        }
                }
-       }
+       } while (!done);
 
        if (!sflag) {
                XStoreName(dpy, DefaultRootWindow(dpy), NULL);