status

statusbar program for dwm
git clone anongit@rnpnr.xyz:status.git
Log | Files | Refs | Feed | README | LICENSE

Commit: 78c76dbb901d5b84d5112edec21f5ec287698475
Parent: 4f40a9da065ed4530e34eae267193e936086e99e
Author: Randy Palamar
Date:   Fri, 27 Dec 2024 15:07:21 -0700

script.c: update to new structure

Diffstat:
Mblocks/script.c | 26++++++++++++++++----------
Mconfig.def.h | 1+
2 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/blocks/script.c b/blocks/script.c @@ -1,15 +1,21 @@ /* See LICENSE for license details. */ -static size_t -script(struct Block *b) +static BLOCK_UPDATE_FN(script_update) { - FILE *fp; + char *out = ""; - if ((fp = popen(b->arg, "r")) == NULL) - die("popen()\n"); - - if (fgets(buf, sizeof(buf), fp) != NULL) - buf[strcspn(buf, "\n")] = 0; - pclose(fp); + /* TODO(rnp): don't use c-runtime for this */ + FILE *fp = popen(b->arg, "r"); + if (fp) { + if (fgets(buffer, sizeof(buffer), fp)) { + buffer[strcspn(buffer, "\n")] = 0; + out = buffer; + } + pclose(fp); + } + b->len = snprintf(b->data, sizeof(b->data), b->fmt, out); +} - return buf[0]? snprintf(b->curstr, LEN(b->curstr), b->fmt, buf) : 0; +static BLOCK_INIT_FN(script_init) +{ + script_update(b); } diff --git a/config.def.h b/config.def.h @@ -26,6 +26,7 @@ static struct bat_arg ba = {.bat = s8("BAT0")}; * battery_info battery percentage and status (struct bat_arg *) * backlight percentage (s8 *) backlight name * date date and time (char *) fmt ("%R") + * script run specified script (char *) full script (echo foo | bar) */ /* NOTE: X(name, statusline_format, interval, argument) *