blob: bbb80428e8661273c0ab4bf7a3aa1bfe271e5783 (
plain)
1 /**
2 * I3cstatus prints a configurable status bar for the i3 window manager
3 * Copyright (C) 2020 Aaron Ball <nullspoon@oper.io>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "config_shell.h"
19
20 void config_shell_init(struct node* n) {
21 n->data = malloc(sizeof(struct config_shell));
22 n->type = CTYPE_SHELL;
23 n->loadfunc = &config_shell_load;
24 n->loadkey = &load_shell_key;
25 }
26
27 void load_shell_key(struct node* n, char* key, char* val) {
28 struct config_shell* data = (struct config_shell*) n->data;
29
30 if(strcmp(key, "script") == 0) {
31 strcpy(data->script, val);
32 if(n->label[0] == '\0')
33 sprintf(n->label, "%s", val);
34 } else {
35 printf("ERROR: Unknown shell key %s\n", key);
36 }
37 }
38
39 int config_shell_load(struct node* n) {
40 struct config_shell* data = (struct config_shell*) n->data;
41 FILE* pipe;
42 char buf[4096];
43
44 // Call the configured script
45 pipe = popen(data->script, "r");
46 fgets(buf, 4096, pipe);
47 pclose(pipe);
48
49 sprintf(n->text, "%s", trim(buf));
50 return 0;
51 }
|