-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod_battery
executable file
·34 lines (25 loc) · 842 Bytes
/
mod_battery
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
#!/usr/bin/env bash
. .dzenbarrc
MONITOR=${1}
PIPE_LINE=${2}
prev_status=""
while true; do
capacity="$(cat "${BATTERY}/capacity")"
status=$(sed "s/Discharging/-/;s/Charging/ /;s/Not charging/n/;s/Unknown/u/;s/Full//" "${BATTERY}/status")
if [[ "${status}" != "${prev_status}" ]]; then
if [[ "$(type -t BATTERY__callback_on_battery)" == "function" ]] && [[ "${status}" == "-" ]]; then
BATTERY__callback_on_battery
elif [[ "$(type -t BATTERY__callback_on_cable)" == "function" ]]; then
BATTERY__callback_on_cable
fi
fi
prev_status="${status}"
if [[ "${capacity}" -le 25 ]] && [[ "${status}" == "-" ]]; then
status="!${status}"
fi
if [[ "${status}" != "" ]]; then
status="[${status}] "
fi
putLineToPipeFile ${MONITOR} ${PIPE_LINE} " $(iconColor 'battery') ${status}${capacity}%"
sleep ${BATTERY_UPDATE}
done