aboutsummaryrefslogtreecommitdiff
path: root/battery-checknow
blob: ed18565340eec789e72992317c54a3f36488fd14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/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"
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
fi

echo "$status" > "$file"

Generated with cgit - Back to sebastiano.tronto.net