blob: 66bbd60b7099bab846f1a2a3dbe161f45f8b1528 (
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 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"
|