1 #!/usr/bin/dash
2
3 # dwmstatus
4
5 BAT=BAT0;
6
7 ROOT=/sys/class/power_supply;
8 ENERGY=energy;
9 NOW=_now;
10 FULL=_full;
11 STATUS=status;
12
13 # ROOT=/proc/acpi/battery/; # old
14 # ENERGY=charge; # old
15
16 nowF="$ROOT/$BAT/$ENERGY$NOW";
17 fullF="$ROOT/$BAT/$ENERGY$FULL";
18 statusF="$ROOT/$BAT/$STATUS";
19
20 showDate(){
21 date "+%a %b %d %H:%M";
22 };
23
24 showBattery(){
25 local now full status
26 now=$(cat "$nowF");
27 full=$(cat "$fullF");
28 status="$(cat "$statusF")";
29 printf "%0.2f%% (%s)" "$(echo "($now/$full)*100" | bc -l)" "$status";
30 };
31
32 setBar(){
33 xsetroot -name "$(showBattery) $1"&
34 }
35
36 curDate="$(showDate)";
37 setBar "$curDate";
38 sleep "$((59-$(date +%S))).9";
39 while true;
40 do
41 newDate="$(showDate)";
42 while [ "$curDate" = "$newDate" ];
43 do
44 sleep ".1";
45 newDate="$(showDate)";
46 done;
47 curDate="$newDate";
48 setBar "$curDate";
49 sleep 59.9;
50 done
51
52 # vim: ft=sh