diff options
author | Aaron Ball <nullspoon@oper.io> | 2020-11-12 09:57:45 -0700 |
---|---|---|
committer | Aaron Ball <nullspoon@oper.io> | 2020-11-12 09:57:45 -0700 |
commit | ecf1d2ae94b46b8c0cffb3b1e8a0295e705c2a5e (patch) | |
tree | bfa833b91fc22397e2c23f2fe57533e7e6c80b43 | |
parent | e5d0257f562ae4ad0a29e4cd8160d655a6be4955 (diff) | |
parent | c3c41441948b856d39ba794bc2616f1bab0f6eed (diff) | |
download | i3cstat-ecf1d2ae94b46b8c0cffb3b1e8a0295e705c2a5e.tar.gz i3cstat-ecf1d2ae94b46b8c0cffb3b1e8a0295e705c2a5e.tar.xz |
Merge branch 'implement_config_shell'
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | i3cstat.conf.sample | 5 | ||||
-rw-r--r-- | src/config.c | 3 | ||||
-rw-r--r-- | src/config.h | 1 | ||||
-rw-r--r-- | src/config_shell.c | 51 | ||||
-rw-r--r-- | src/config_shell.h | 40 | ||||
-rw-r--r-- | src/main.c | 2 |
7 files changed, 105 insertions, 2 deletions
@@ -36,7 +36,10 @@ config_mem: common config_node config_net: common config_node cc $(CCOPTS) src/config_net.c -c -o obj/config_net.o -config: config_node config_bat config_fs config_net config_date config_time config_mem config_cpu +config_shell: common config_node + cc $(CCOPTS) src/config_shell.c -c -o obj/config_shell.o + +config: config_node config_bat config_fs config_net config_date config_time config_mem config_cpu config_shell cc $(CCOPTS) src/config.c -c -o obj/config.o install: diff --git a/i3cstat.conf.sample b/i3cstat.conf.sample index d267e83..ad06dac 100644 --- a/i3cstat.conf.sample +++ b/i3cstat.conf.sample @@ -41,3 +41,8 @@ label = GMT: [date] tz = Greenwich + +[shell] +label = Stuff done: +script = /usr/bin/dostuff.sh +interval = 5 diff --git a/src/config.c b/src/config.c index eeaa5fe..07bbc2f 100644 --- a/src/config.c +++ b/src/config.c @@ -91,6 +91,9 @@ struct node* config_load(char* path) { } else if(strcmp(section, "cpu") == 0) { cur = node_new(&config_cpu_init); + + } else if(strcmp(section, "shell") == 0) { + cur = node_new(&config_shell_init); } if(!list) diff --git a/src/config.h b/src/config.h index 8364ab5..de0e294 100644 --- a/src/config.h +++ b/src/config.h @@ -27,5 +27,6 @@ #include "config_time.h" #include "config_fs.h" #include "config_bat.h" +#include "config_shell.h" struct node* config_load(char*); diff --git a/src/config_shell.c b/src/config_shell.c new file mode 100644 index 0000000..bbb8042 --- /dev/null +++ b/src/config_shell.c @@ -0,0 +1,51 @@ +/** + * I3cstatus prints a configurable status bar for the i3 window manager + * Copyright (C) 2020 Aaron Ball <nullspoon@oper.io> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#include "config_shell.h" + +void config_shell_init(struct node* n) { + n->data = malloc(sizeof(struct config_shell)); + n->type = CTYPE_SHELL; + n->loadfunc = &config_shell_load; + n->loadkey = &load_shell_key; +} + +void load_shell_key(struct node* n, char* key, char* val) { + struct config_shell* data = (struct config_shell*) n->data; + + if(strcmp(key, "script") == 0) { + strcpy(data->script, val); + if(n->label[0] == '\0') + sprintf(n->label, "%s", val); + } else { + printf("ERROR: Unknown shell key %s\n", key); + } +} + +int config_shell_load(struct node* n) { + struct config_shell* data = (struct config_shell*) n->data; + FILE* pipe; + char buf[4096]; + + // Call the configured script + pipe = popen(data->script, "r"); + fgets(buf, 4096, pipe); + pclose(pipe); + + sprintf(n->text, "%s", trim(buf)); + return 0; +} diff --git a/src/config_shell.h b/src/config_shell.h new file mode 100644 index 0000000..7cb8608 --- /dev/null +++ b/src/config_shell.h @@ -0,0 +1,40 @@ +/** + * I3cstatus prints a configurable status bar for the i3 window manager + * Copyright (C) 2020 Aaron Ball <nullspoon@oper.io> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef CONFIG_SHELL +#define CONFIG_SHELL + +#define CTYPE_SHELL 80 + +#include <stdio.h> +#include <string.h> +#include <time.h> +#include "common.h" +#include "config_node.h" + +struct config_shell { + char script[128]; + char label[128]; +}; + +void config_shell_init(struct node*); + +int config_shell_load(struct node*); + +void load_shell_key(struct node*, char*, char*); + +#endif @@ -55,7 +55,7 @@ int main(int argc, char* argv[]) { while(1) { printf("[\n"); while(cur) { - if(time(NULL) - cur->lastrun > cur->interval) { + if(time(NULL) - cur->lastrun >= cur->interval) { cur->loadfunc(cur); cur->lastrun = time(NULL); } |