aboutsummaryrefslogtreecommitdiff
path: root/src/print_cmd.c
diff options
context:
space:
mode:
authorMart Lubbers2016-01-17 18:05:11 +0100
committerCamil Staps2019-12-11 17:29:33 +0100
commit625518acd7c62acde2d6d150272fa17a45eb3ce9 (patch)
tree7142278a1694f3e2fda2276e1277525ee31a7632 /src/print_cmd.c
parentMerge pull request #373 from zsugabubus/fix-memory (diff)
Add support for custom commandsHEADmaster
Add the cmd option in the config that runs a shell command.
Diffstat (limited to 'src/print_cmd.c')
-rw-r--r--src/print_cmd.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/print_cmd.c b/src/print_cmd.c
new file mode 100644
index 0000000..a7ac575
--- /dev/null
+++ b/src/print_cmd.c
@@ -0,0 +1,23 @@
+// vim:ts=4:sw=4:expandtab
+#include <stdio.h>
+#include <string.h>
+#include <yajl/yajl_gen.h>
+#include <yajl/yajl_version.h>
+
+#include "i3status.h"
+
+void print_cmd(yajl_gen json_gen, char *buffer, const char *cmd) {
+ char *outwalk = buffer;
+ char path[1024];
+ FILE *fp;
+ fp = popen(cmd, "r");
+ fgets(path, sizeof(path) - 1, fp);
+ pclose(fp);
+
+ char *nl = index(path, '\n');
+ if (nl != NULL) {
+ *nl = '\0';
+ }
+ maybe_escape_markup(path, &outwalk);
+ OUTPUT_FULL_TEXT(buffer);
+}