summary refs log tree commit diff
path: root/bin/lowbat
blob: 90702a167d3516849130a97f07545281051654a8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/sh

set -e

acpi -b | awk -F'[,:%]' '{print $2, $3}' | {
	read -r status capacity

	if [[ $status -eq "Discharging" ]]; then
		if [[ $capacity -lt 10 ]]; then
			echo "battery capacity: $capacity"
			notify-send "battery low" "System will hibernate at 5%"
		fi
		if [[ $capacity -lt 5 ]]; then
			echo "hibernating"
			notify-send "battery low" "System will hibernate now"
			systemctl hibernate
		fi
	fi
}