From 625518acd7c62acde2d6d150272fa17a45eb3ce9 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Sun, 17 Jan 2016 18:05:11 +0100 Subject: Add support for custom commands Add the cmd option in the config that runs a shell command. --- src/print_cmd.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/print_cmd.c (limited to 'src/print_cmd.c') 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 +#include +#include +#include + +#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); +} -- cgit v1.2.3