You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
xmonad/battery-monitor.sh

26 lines
923 B

9 years ago
#!/bin/bash
set -e
trap 'xmessage -nearmouse "WARNING: battery monitor died!"' EXIT
was_notified=0
while true; do
acpi_data=$(acpi -b | grep -v 'rate information unavailable' | head -n1)
9 years ago
status=$(echo -n "$acpi_data" | awk -F'[,:%]' '{print $2}')
capacity=$(echo -n "$acpi_data" | awk -F'[,:%]' '{print $3}')
echo "Status: $status; Capacity: $capacity; was_notified: $was_notified"
if [[ "$status" =~ "Charging" ]]; then
was_notified=0
fi
if [[ "$status" =~ "Discharging" && "$capacity" -lt 15 && "$was_notified" = 0 ]]; then
9 years ago
xmessage -nearmouse "$acpi_data"&
was_notified=1
fi
if [[ "$status" =~ "Discharging" && "$capacity" -lt 10 ]]; then
echo -e "Battery critical, suspending\n$acpi_data" | xmessage -nearmouse -file -&
9 years ago
sleep 5
systemctl suspend
sleep 600 # Wait 10 minutes, so we only hibernate once
9 years ago
fi
sleep 10
done