1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
diff --git a/dwmstatus.c b/dwmstatus.c
index d2a4b03..4b5e093 100644
--- a/dwmstatus.c
+++ b/dwmstatus.c
@@ -17,8 +17,6 @@
#include <X11/Xlib.h>
-char *tzargentina = "America/Buenos_Aires";
-char *tzutc = "UTC";
char *tzberlin = "Europe/Berlin";
static Display *dpy;
@@ -89,7 +87,7 @@ loadavg(void)
if (getloadavg(avgs, 3) < 0)
return smprintf("");
- return smprintf("%.2f %.2f %.2f", avgs[0], avgs[1], avgs[2]);
+ return smprintf("%.2f", avgs[1]);
}
char *
@@ -155,7 +153,7 @@ getbattery(char *base)
} else if(!strncmp(co, "Charging", 8)) {
status = '+';
} else {
- status = '?';
+ status = '\0';
}
if (remcap < 0 || descap < 0)
@@ -175,47 +173,49 @@ gettemperature(char *base, char *sensor)
return smprintf("%02.0f°C", atof(co) / 1000);
}
+char *
+getpartition(char *partition) {
+ char *co = smprintf("df -lh | grep %s | tr -s ' ' | cut -d ' ' -f 4 | tr -d '\n'", partition);
+ FILE *fd = popen(co, "r");
+ if (fd == NULL)
+ return smprintf("invalid");
+
+ char ret[8];
+ if (fgets(ret, 8, fd) == NULL)
+ return smprintf("invalid");
+
+ if (pclose(fd) == -1)
+ return smprintf("invalid");
+
+ return smprintf("%s", ret);
+}
+
int
main(void)
{
char *status;
char *avgs;
char *bat;
- char *bat1;
- char *tmar;
- char *tmutc;
char *tmbln;
- char *t0, *t1, *t2;
+ char *partition;
if (!(dpy = XOpenDisplay(NULL))) {
fprintf(stderr, "dwmstatus: cannot open display.\n");
return 1;
}
- for (;;sleep(60)) {
+ for (;;sleep(10)) {
avgs = loadavg();
+ partition = getpartition("/$");
bat = getbattery("/sys/class/power_supply/BAT0");
- bat1 = getbattery("/sys/class/power_supply/BAT1");
- tmar = mktimes("%H:%M", tzargentina);
- tmutc = mktimes("%H:%M", tzutc);
- tmbln = mktimes("KW %W %a %d %b %H:%M %Z %Y", tzberlin);
- t0 = gettemperature("/sys/devices/virtual/hwmon/hwmon0", "temp1_input");
- t1 = gettemperature("/sys/devices/virtual/hwmon/hwmon2", "temp1_input");
- t2 = gettemperature("/sys/devices/virtual/hwmon/hwmon4", "temp1_input");
-
- status = smprintf("T:%s|%s|%s L:%s B:%s|%s A:%s U:%s %s",
- t0, t1, t2, avgs, bat, bat1, tmar, tmutc,
- tmbln);
+ tmbln = mktimes("%a %d %b %H:%M", tzberlin);
+
+ status = smprintf(" %s | %s | %s | %s",
+ avgs, partition, bat, tmbln);
setstatus(status);
- free(t0);
- free(t1);
- free(t2);
free(avgs);
free(bat);
- free(bat1);
- free(tmar);
- free(tmutc);
free(tmbln);
free(status);
}
|