CFG_END()
};
+ cfg_opt_t path_exists_opts[] = {
+ CFG_STR("path", NULL, CFGF_NONE),
+ CFG_STR("format", "%title: %status", CFGF_NONE),
+ CFG_CUSTOM_COLOR_OPTS,
+ CFG_END()
+ };
+
cfg_opt_t wireless_opts[] = {
CFG_STR("format_up", "W: (%quality at %essid, %bitrate) %ip", CFGF_NONE),
CFG_STR("format_down", "W: down", CFGF_NONE),
CFG_STR_LIST("order", "{}", CFGF_NONE),
CFG_SEC("general", general_opts, CFGF_NONE),
CFG_SEC("run_watch", run_watch_opts, CFGF_TITLE | CFGF_MULTI),
+ CFG_SEC("path_exists", path_exists_opts, CFGF_TITLE | CFGF_MULTI),
CFG_SEC("wireless", wireless_opts, CFGF_TITLE | CFGF_MULTI),
CFG_SEC("ethernet", ethernet_opts, CFGF_TITLE | CFGF_MULTI),
CFG_SEC("battery", battery_opts, CFGF_TITLE | CFGF_MULTI),
SEC_CLOSE_MAP;
}
+ CASE_SEC_TITLE("path_exists") {
+ SEC_OPEN_MAP("path_exists");
+ print_path_exists(json_gen, buffer, title, cfg_getstr(sec, "path"), cfg_getstr(sec, "format"));
+ SEC_CLOSE_MAP;
+ }
+
CASE_SEC_TITLE("disk") {
SEC_OPEN_MAP("disk_info");
print_disk_info(json_gen, buffer, title, cfg_getstr(sec, "format"));
const char *get_ip_addr();
void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface, const char *format_up, const char *format_down);
void print_run_watch(yajl_gen json_gen, char *buffer, const char *title, const char *pidfile, const char *format);
+void print_path_exists(yajl_gen json_gen, char *buffer, const char *title, const char *path, const char *format);
void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const char *path, const char *format, int);
void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format);
void print_eth_info(yajl_gen json_gen, char *buffer, const char *interface, const char *format_up, const char *format_down);
order += "ipv6"
order += "disk /"
order += "run_watch DHCP"
-order += "run_watch VPN"
+order += "run_watch VPNC"
+order += "path_exists VPN"
order += "wireless wlan0"
order += "ethernet eth0"
order += "battery 0"
pidfile = "/var/run/dhclient*.pid"
}
-run_watch VPN {
+run_watch VPNC {
+ # file containing the PID of a vpnc process
pidfile = "/var/run/vpnc/pid"
}
+path_exists VPN {
+ # path exists when a VPN tunnel launched by nmcli/nm-applet is active
+ path = "/proc/sys/net/ipv4/conf/tun0"
+}
+
tztime local {
format = "%Y-%m-%d %H:%M:%S"
}
*Example format*: +%title: %status+
+=== Path-exists
+
+Checks if the given path exists in the filesystem. You can use this to check if
+something is active, like for example a VPN tunnel managed by NetworkManager.
+
+*Example order*: +path_exists VPN+
+
+*Example format*: +%title: %status+
+
=== Wireless
Gets the link quality and ESSID of the given wireless network interface. You
#include <stdlib.h>
#include <unistd.h>
#include <sys/fcntl.h>
+#include <sys/stat.h>
#include "i3status.h"
--- /dev/null
+#include <stdio.h>
+#include <string.h>
+#include <yajl/yajl_gen.h>
+#include <yajl/yajl_version.h>
+#include <sys/stat.h>
+#include "i3status.h"
+
+void print_path_exists(yajl_gen json_gen, char *buffer, const char *title, const char *path, const char *format) {
+ const char *walk;
+ char *outwalk = buffer;
+ struct stat st;
+ const bool exists = (stat(path, &st) == 0);
+
+ INSTANCE(path);
+
+ START_COLOR((exists ? "color_good" : "color_bad"));
+
+ for (walk = format; *walk != '\0'; walk++) {
+ if (*walk != '%') {
+ *(outwalk++) = *walk;
+ continue;
+ }
+
+ if (strncmp(walk+1, "title", strlen("title")) == 0) {
+ outwalk += sprintf(outwalk, "%s", title);
+ walk += strlen("title");
+ } else if (strncmp(walk+1, "status", strlen("status")) == 0) {
+ outwalk += sprintf(outwalk, "%s", (exists ? "yes" : "no"));
+ walk += strlen("status");
+ }
+ }
+
+ END_COLOR;
+ OUTPUT_FULL_TEXT(buffer);
+}