Re: [dev] [PATCH slstatus] Add a -1 option flag

From: Daniel Moch <daniel_AT_danielmoch.com>
Date: Sat, 27 Jun 2020 07:02:41 -0400

Any feedback on this? Does this seem like something that should be
added to the wiki as a patch, or something that should be merged?

On Tue, Jun 23, 2020 at 04:35:43PM -0400, Daniel Moch wrote:
> 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 | 5 ++++-
> slstatus.c | 9 ++++++---
> 2 files changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/slstatus.1 b/slstatus.1
> index da1a99a..d802037 100644
> --- a/slstatus.1
> +++ b/slstatus.1
> _AT_@ -1,4 +1,4 @@
> -.Dd 2017-08-10
> +.Dd 2020-06-23
> .Dt SLSTATUS 1
> .Os
> .Sh NAME
> _AT_@ -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
> _AT_@ -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
> diff --git a/slstatus.c b/slstatus.c
> index 96fa5b6..f1f0741 100644
> --- a/slstatus.c
> +++ b/slstatus.c
> _AT_@ -42,7 +42,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
> _AT_@ -57,6 +57,9 @@ main(int argc, char *argv[])
>
> sflag = 0;
> ARGBEGIN {
> + case '1':
> + done = 1;
> + /* fallthrough */
> case 's':
> sflag = 1;
> break;
> _AT_@ -77,7 +80,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:");
> }
> _AT_@ -124,7 +127,7 @@ main(int argc, char *argv[])
> }
> }
> }
> - }
> + } while (!done);
>
> if (!sflag) {
> XStoreName(dpy, DefaultRootWindow(dpy), NULL);
> --
> 2.27.0
>
>

-- 
Daniel Moch
daniel_AT_danielmoch.com
http://djmoch.org

Received on Sat Jun 27 2020 - 13:02:41 CEST

This archive was generated by hypermail 2.3.0 : Sat Jun 27 2020 - 13:12:08 CEST