Added shell command function
authorAaron Marcher <info@nulltime.net>
Mon, 15 Aug 2016 10:23:35 +0000 (12:23 +0200)
committerAaron Marcher (drkhsh) <info@nulltime.net>
Mon, 15 Aug 2016 10:23:35 +0000 (12:23 +0200)
README.md
config.def.h
slstatus.c

index 7e2ac204ec12e2e88ae51cfd7ee5542dd4a47575..404977fbdb746932ace82fa8f947eeef8610fdf8 100644 (file)
--- a/README.md
+++ b/README.md
@@ -11,6 +11,7 @@ The following information is included:
 
 - battery percentage
 - cpu usage (in percent)
+- custom shell commands
 - date and time
 - disk numbers (free storage, percentage, total storage and used storage)
 - available entropy
index b272a66898efe59a57efde21209f22ca7133f67c..c9da3143d4237037b05c346122e5bc9cd9865e88 100644 (file)
@@ -27,6 +27,7 @@ static unsigned int update_interval = 1;
 - ram_perc (ram usage in percent) [argument: NULL]
 - ram_total (ram usage in percent) [argument: NULL]
 - ram_used (ram usage in percent) [argument: NULL]
+- run_command (run custom shell command) [argument: command]
 - temp (temperature in degrees) [argument: temperature file]
 - uid (uid of current user) [argument: NULL]
 - username (username of current user) [argument: NULL]
index 6d56000825a0936616735df0b3f88445a7ffe5d9..a5807dd99b010b9e1c809d73d4a370dc21ba106e 100644 (file)
@@ -444,6 +444,32 @@ ram_used(const char *null)
     return smprintf("%f", (float)used / 1024 / 1024);
 }
 
+/* custom shell command */
+char *
+run_command(const char* command)
+{
+       FILE *fp;
+       char buffer[64];
+
+    /* try to open the command output */
+       if (!(fp = popen(command, "r"))) {
+        fprintf(stderr, "Could not get command output for: %s.\n", command);
+        return smprintf("n/a");
+    }
+
+    /* get command output text, save it to buffer */
+       fgets(buffer, sizeof(buffer)-1, fp);
+
+    /* close it again */
+       pclose(fp);
+
+    /* add nullchar at the end */
+       buffer[strlen(buffer) - 1] = '\0';
+
+    /* return the output */
+       return smprintf("%s", buffer);
+}
+
 /* temperature */
 char *
 temp(const char *file)