Add support for path_exists directive.
Patch status: merged
Patch by Kinware AB
To apply this patch, use:
curl http://cr.i3wm.org/patch/326/raw.patch | git am
b/i3status.c
| 18 |
@@ -210,6 +210,13 @@ int main(int argc, char *argv[]) {
|
| 19 |
CFG_END() |
| 20 |
}; |
| 21 |
|
| 22 |
+ cfg_opt_t path_exists_opts[] = {
|
| 23 |
+ CFG_STR("path", NULL, CFGF_NONE),
|
| 24 |
+ CFG_STR("format", "%title: %status", CFGF_NONE),
|
| 25 |
+ CFG_CUSTOM_COLOR_OPTS, |
| 26 |
+ CFG_END() |
| 27 |
+ }; |
| 28 |
+ |
| 29 |
cfg_opt_t wireless_opts[] = {
|
| 30 |
CFG_STR("format_up", "W: (%quality at %essid, %bitrate) %ip", CFGF_NONE),
|
| 31 |
CFG_STR("format_down", "W: down", CFGF_NONE),
|
| 32 |
@@ -297,6 +304,7 @@ int main(int argc, char *argv[]) {
|
| 33 |
CFG_STR_LIST("order", "{}", CFGF_NONE),
|
| 34 |
CFG_SEC("general", general_opts, CFGF_NONE),
|
| 35 |
CFG_SEC("run_watch", run_watch_opts, CFGF_TITLE | CFGF_MULTI),
|
| 36 |
+ CFG_SEC("path_exists", path_exists_opts, CFGF_TITLE | CFGF_MULTI),
|
| 37 |
CFG_SEC("wireless", wireless_opts, CFGF_TITLE | CFGF_MULTI),
|
| 38 |
CFG_SEC("ethernet", ethernet_opts, CFGF_TITLE | CFGF_MULTI),
|
| 39 |
CFG_SEC("battery", battery_opts, CFGF_TITLE | CFGF_MULTI),
|
| 40 |
@@ -480,6 +488,12 @@ int main(int argc, char *argv[]) {
|
| 41 |
SEC_CLOSE_MAP; |
| 42 |
} |
| 43 |
|
| 44 |
+ CASE_SEC_TITLE("path_exists") {
|
| 45 |
+ SEC_OPEN_MAP("path_exists");
|
| 46 |
+ print_path_exists(json_gen, buffer, title, cfg_getstr(sec, "path"), cfg_getstr(sec, "format")); |
| 47 |
+ SEC_CLOSE_MAP; |
| 48 |
+ } |
| 49 |
+ |
| 50 |
CASE_SEC_TITLE("disk") {
|
| 51 |
SEC_OPEN_MAP("disk_info");
|
| 52 |
print_disk_info(json_gen, buffer, title, cfg_getstr(sec, "format")); |
b/include/i3status.h
| 57 |
@@ -152,6 +152,7 @@ void print_ddate(yajl_gen json_gen, char *buffer, const char *format, time_t t); |
| 58 |
const char *get_ip_addr(); |
| 59 |
void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface, const char *format_up, const char *format_down); |
| 60 |
void print_run_watch(yajl_gen json_gen, char *buffer, const char *title, const char *pidfile, const char *format); |
| 61 |
+void print_path_exists(yajl_gen json_gen, char *buffer, const char *title, const char *path, const char *format); |
| 62 |
void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const char *path, const char *format, int); |
| 63 |
void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format); |
| 64 |
void print_eth_info(yajl_gen json_gen, char *buffer, const char *interface, const char *format_up, const char *format_down); |
b/man/i3status.man
| 69 |
@@ -50,7 +50,8 @@ general {
|
| 70 |
order += "ipv6" |
| 71 |
order += "disk /" |
| 72 |
order += "run_watch DHCP" |
| 73 |
-order += "run_watch VPN" |
| 74 |
+order += "run_watch VPNC" |
| 75 |
+order += "path_exists VPN" |
| 76 |
order += "wireless wlan0" |
| 77 |
order += "ethernet eth0" |
| 78 |
order += "battery 0" |
| 79 |
@@ -81,10 +82,16 @@ run_watch DHCP {
|
| 80 |
pidfile = "/var/run/dhclient*.pid" |
| 81 |
} |
| 82 |
|
| 83 |
-run_watch VPN {
|
| 84 |
+run_watch VPNC {
|
| 85 |
+ # file containing the PID of a vpnc process |
| 86 |
pidfile = "/var/run/vpnc/pid" |
| 87 |
} |
| 88 |
|
| 89 |
+path_exists VPN {
|
| 90 |
+ # path exists when a VPN tunnel launched by nmcli/nm-applet is active |
| 91 |
+ path = "/proc/sys/net/ipv4/conf/tun0" |
| 92 |
+} |
| 93 |
+ |
| 94 |
tztime local {
|
| 95 |
format = "%Y-%m-%d %H:%M:%S" |
| 96 |
} |
| 97 |
@@ -193,6 +200,15 @@ a specific application, such as a VPN client or your DHCP client is running. |
| 98 |
|
| 99 |
*Example format*: +%title: %status+ |
| 100 |
|
| 101 |
+=== Path-exists |
| 102 |
+ |
| 103 |
+Checks if the given path exists in the filesystem. You can use this to check if |
| 104 |
+something is active, like for example a VPN tunnel managed by NetworkManager. |
| 105 |
+ |
| 106 |
+*Example order*: +path_exists VPN+ |
| 107 |
+ |
| 108 |
+*Example format*: +%title: %status+ |
| 109 |
+ |
| 110 |
=== Wireless |
| 111 |
|
| 112 |
Gets the link quality and ESSID of the given wireless network interface. You |
b/src/general.c
| 117 |
@@ -6,6 +6,7 @@ |
| 118 |
#include <stdlib.h> |
| 119 |
#include <unistd.h> |
| 120 |
#include <sys/fcntl.h> |
| 121 |
+#include <sys/stat.h> |
| 122 |
|
| 123 |
#include "i3status.h" |
| 124 |
|
b/src/print_path_exists.c
| 130 |
@@ -0,0 +1,35 @@ |
| 131 |
+#include <stdio.h> |
| 132 |
+#include <string.h> |
| 133 |
+#include <yajl/yajl_gen.h> |
| 134 |
+#include <yajl/yajl_version.h> |
| 135 |
+#include <sys/stat.h> |
| 136 |
+#include "i3status.h" |
| 137 |
+ |
| 138 |
+void print_path_exists(yajl_gen json_gen, char *buffer, const char *title, const char *path, const char *format) {
|
| 139 |
+ const char *walk; |
| 140 |
+ char *outwalk = buffer; |
| 141 |
+ struct stat st; |
| 142 |
+ const bool exists = (stat(path, &st) == 0); |
| 143 |
+ |
| 144 |
+ INSTANCE(path); |
| 145 |
+ |
| 146 |
+ START_COLOR((exists ? "color_good" : "color_bad")); |
| 147 |
+ |
| 148 |
+ for (walk = format; *walk != '\0'; walk++) {
|
| 149 |
+ if (*walk != '%') {
|
| 150 |
+ *(outwalk++) = *walk; |
| 151 |
+ continue; |
| 152 |
+ } |
| 153 |
+ |
| 154 |
+ if (strncmp(walk+1, "title", strlen("title")) == 0) {
|
| 155 |
+ outwalk += sprintf(outwalk, "%s", title); |
| 156 |
+ walk += strlen("title");
|
| 157 |
+ } else if (strncmp(walk+1, "status", strlen("status")) == 0) {
|
| 158 |
+ outwalk += sprintf(outwalk, "%s", (exists ? "yes" : "no")); |
| 159 |
+ walk += strlen("status");
|
| 160 |
+ } |
| 161 |
+ } |
| 162 |
+ |
| 163 |
+ END_COLOR; |
| 164 |
+ OUTPUT_FULL_TEXT(buffer); |
| 165 |
+} |