blob: 4b764885c01fa5f38bf5669afe98c36e95774c2a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#!/bin/sh
# Check battery state, save result to a file. Pop up notification if changed.
# Requires: battery-status, notify-battery
file="${XDG_DATA_HOME:-$HOME/.local/share}/batterystatus"
notify=${NOTIFY:-"notify push"}
low=20
crit=15
new=$(battery-status)
level=$(echo "$new" | sed 's/%.*//')
status=$(echo "$new" | awk '{print $2}')
[ "$status" = "Discharging" ] && [ "$level" -le "$low" ] && status="Low"
[ "$status" = "Discharging" ] && [ "$level" -le "$crit" ] && status="Critical"
if [ "$status" != "$(cat "$file")" ] || [ "$status" = "Critical" ]; then
$notify "Battery: $(battery-status)"
fi
echo "$status" > "$file"
|