commit dbcfb771199229e829e23019e063f6a7688c19e5
parent a5b9807743773ea1c49292557efba7a714924691
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Thu, 13 Apr 2023 13:29:53 -0700
Add firstline patch to slstatus
This adds a component to slstatus which reads the first line from
a file.
Diffstat:
1 file changed, 68 insertions(+), 0 deletions(-)
diff --git a/local/src/src/forks/slstatus/patches/a-first_line.diff b/local/src/src/forks/slstatus/patches/a-first_line.diff
@@ -0,0 +1,68 @@
+Author: Jacob R. Edwards <jacob@jacobedwards.org>
+Date: 2023-04-07
+
+Add "first_line" component to slstatus. This component simply returns
+the first line of a named file, or NULL couldn't be retrieved for
+some reason.
+
+My purpose for this component is to put status messages into a file
+for slstatus to display.
+
+diff -Prup slstatus-orig/components/first_line.c slstatus/components/first_line.c
+--- slstatus-orig/components/first_line.c Wed Dec 31 16:00:00 1969
++++ slstatus/components/first_line.c Fri Apr 7 08:27:45 2023
+@@ -0,0 +1,22 @@
++/* See LICENSE file for copyright and license details. */
++
++#include <stdio.h>
++#include <string.h>
++
++#include "../util.h"
++
++const char *
++first_line(const char *path)
++{
++ char buf[1024];
++ FILE *file;
++
++ file = fopen(path, "r");
++ if (!file || !fgets(buf, sizeof(buf), file))
++ return NULL;
++ buf[strcspn(buf, "\n")] = 0;
++ if (fclose(file))
++ warn("unable to close %s:", path);
++
++ return bprintf("%s", buf);
++}
+diff -Prup slstatus-orig/config.def.h slstatus/config.def.h
+--- slstatus-orig/config.def.h Fri Apr 7 08:26:28 2023
++++ slstatus/config.def.h Fri Apr 7 08:27:30 2023
+@@ -62,6 +62,7 @@ static const char unknown_str[] = "n/a";
+ * NULL on OpenBSD
+ * wifi_perc WiFi signal in percent interface name (wlan0)
+ * wifi_essid WiFi ESSID interface name (wlan0)
++ * first_line first line from a file file name
+ */
+ static const struct arg args[] = {
+ /* function format argument */
+diff -Prup slstatus-orig/slstatus.h slstatus/slstatus.h
+--- slstatus-orig/slstatus.h Fri Apr 7 08:26:40 2023
++++ slstatus/slstatus.h Fri Apr 7 08:28:03 2023
+@@ -82,3 +82,6 @@ const char *vol_perc(const char *card);
+ /* wifi */
+ const char *wifi_perc(const char *interface);
+ const char *wifi_essid(const char *interface);
++
++/* file */
++const char *first_line(const char *path);
+diff -Prup slstatus-orig/Makefile slstatus/Makefile
+--- Makefile.orig Fri Apr 7 08:44:18 2023
++++ Makefile Fri Apr 7 08:44:26 2023
+@@ -11,6 +11,7 @@ COM =\
+ components/datetime\
+ components/disk\
+ components/entropy\
++ components/first_line\
+ components/hostname\
+ components/ip\
+ components/kernel_release\