auto_hibernate.sh 417 B

12345678910111213
  1. #!/bin/bash
  2. stat=$(cat /sys/class/power_supply/BAT0/status)
  3. batperc=$(cat /sys/class/power_supply/BAT0/capacity)
  4. if [[ $stat = "Discharging" ]]; then
  5. if [ $batperc -le 8 ]; then
  6. notify-send 'HEY! Your battery is low!' 'Save your work!!' -i battery-low -t 20000
  7. fi
  8. if [ $batperc -eq 1 ]; then
  9. notify-send 'Doing you a favor, buddy.' -i battery-low -u critical
  10. sleep 2 && systemctl hibernate
  11. fi
  12. fi