Added support for i3status to display file contents
Patch status: superseded
Patch by EscapedNull
To apply this patch, use:
curl http://cr.i3wm.org/patch/392/raw.patch | git am
b/i3status.c
15 |
@@ -302,6 +302,15 @@ int main(int argc, char *argv[]) { |
16 |
CFG_END() |
17 |
}; |
18 |
|
19 |
+ cfg_opt_t file_opts[] = { |
20 |
+ CFG_STR("format", "%contents (%mtime_diff)", CFGF_NONE), |
21 |
+ CFG_INT("line", 1, CFGF_NONE), |
22 |
+ CFG_INT("skip", 0, CFGF_NONE), |
23 |
+ CFG_INT("limit", 4096, CFGF_NONE), |
24 |
+ CFG_STR("mtime_format", "%H:%M:%S", CFGF_NONE), |
25 |
+ CFG_END() |
26 |
+ }; |
27 |
+ |
28 |
cfg_opt_t opts[] = { |
29 |
CFG_STR_LIST("order", "{}", CFGF_NONE), |
30 |
CFG_SEC("general", general_opts, CFGF_NONE), |
31 |
@@ -319,6 +328,7 @@ int main(int argc, char *argv[]) { |
32 |
CFG_SEC("ddate", ddate_opts, CFGF_NONE), |
33 |
CFG_SEC("load", load_opts, CFGF_NONE), |
34 |
CFG_SEC("cpu_usage", usage_opts, CFGF_NONE), |
35 |
+ CFG_SEC("file", file_opts, CFGF_TITLE | CFGF_MULTI), |
36 |
CFG_CUSTOM_COLOR_OPTS, |
37 |
CFG_END() |
38 |
}; |
39 |
@@ -547,6 +557,12 @@ int main(int argc, char *argv[]) { |
40 |
print_cpu_usage(json_gen, buffer, cfg_getstr(sec, "format")); |
41 |
SEC_CLOSE_MAP; |
42 |
} |
43 |
+ |
44 |
+ CASE_SEC_TITLE("file") { |
45 |
+ SEC_OPEN_MAP("file"); |
46 |
+ print_file(json_gen, buffer, title, cfg_getstr(sec, "format"), cfg_getint(sec, "line"), cfg_getint(sec, "skip"), cfg_getint(sec, "limit"), cfg_getstr(sec, "mtime_format")); |
47 |
+ SEC_CLOSE_MAP; |
48 |
+ } |
49 |
} |
50 |
if (output_format == O_I3BAR) { |
51 |
yajl_gen_array_close(json_gen); |
b/include/i3status.h
56 |
@@ -158,6 +158,7 @@ void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format); |
57 |
void print_eth_info(yajl_gen json_gen, char *buffer, const char *interface, const char *format_up, const char *format_down); |
58 |
void print_load(yajl_gen json_gen, char *buffer, const char *format, const float max_threshold); |
59 |
void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *fmt_muted, const char *device, const char *mixer, int mixer_idx); |
60 |
+void print_file(yajl_gen json_gen, char *buffer, const char *title, const char *format, const int line, const int skip, const int limit, const char *mtime_format); |
61 |
bool process_runs(const char *path); |
62 |
|
63 |
/* socket file descriptor for general purposes */ |
b/man/i3status.man
68 |
@@ -376,6 +376,49 @@ volume master { |
69 |
} |
70 |
------------------------------------------------------------- |
71 |
|
72 |
+=== File |
73 |
+ |
74 |
+Prints a file's contents at the specified line, and/or its modification time. |
75 |
+ |
76 |
++format+ specifies how the file should be displayed. It has the following variables: |
77 |
+ |
78 |
++%contents+ displays the file's contents according to +line+, +skip+, and +limit+. |
79 |
+ |
80 |
++%mtime+ shows the file's modification time according to +mtime_format+. By default, |
81 |
+"%H:%M:%S" is used. |
82 |
+ |
83 |
++%mtime_diff+ expands to the file's age in a coarse, concise, human-readable format. |
84 |
+For example, "1y" or "28m". Only the largest unit of time is displayed. |
85 |
+ |
86 |
++mtime_format+ defines which units of time should be displayed as specified by |
87 |
+strftime(3). |
88 |
+ |
89 |
++line+ specifies which line (delimited by "\r", "\n", or "\r\n") should be displayed. |
90 |
+Negative values for +line+ will be counted from the bottom. For example, +line = -1+ |
91 |
+behaves similarly to tail(1). If the line does not exist, +%contents+ will be blank. |
92 |
+Note that many plain text files contain a trailing newline, in which case you should |
93 |
+subtract one from the desired +line+ when using a negative value. |
94 |
+ |
95 |
+i3status removes +skip+ bytes from the beginning of the specified line before |
96 |
+displaying it. Similarly, i3status will not display more than +limit+ bytes |
97 |
+after +skip+. |
98 |
+ |
99 |
+*Example order*: +file /var/log/Xorg.0.log+ |
100 |
+ |
101 |
+*Example format*: +(%mtime_diff) %contents+ |
102 |
+*Example format_mtime*: +%a %Y/%m/%d %H:%M:%S+ |
103 |
+ |
104 |
+*Example configuration*: |
105 |
+------------------------------------------------------------- |
106 |
+file /var/log/Xorg.0.log { |
107 |
+ format = "[%mtime] %contents (%mtime_diff ago)" |
108 |
+ mtime_format = "%a %H:%M:%S" |
109 |
+ line = -2 |
110 |
+ skip = 10 |
111 |
+ limit = 20 |
112 |
+} |
113 |
+------------------------------------------------------------- |
114 |
+ |
115 |
== Using i3status with dzen2 |
116 |
|
117 |
After installing dzen2, you can directly use it with i3status. Just ensure that |