auto-hibernate.sh 620 B

12345678910111213141516
  1. #!/bin/bash
  2. stat=$(cat /sys/class/power_supply/BAT0/uevent | grep STATUS | cut -f2 -d=)
  3. batperc=$(cat /sys/class/power_supply/BAT0/uevent | grep CAPACITY | cut -f2 -d=)
  4. if [[ $stat -eq "Discharging" ]]; then
  5. export DISPLAY=:0.0
  6. if [[ $batperc -le 8 ]]; then
  7. # This will, and should, spam me when my battery gets low.
  8. notify-send 'HEY! Your battery is low!' 'Save your work!!' --icon=battery-low
  9. fi
  10. if [[ $batperc -eq 0 ]]; then
  11. # TODO: Find a way to not use sudo/editing sudoers
  12. notify-send 'Doing you a favor, buddy.' --icon=battery-low
  13. sleep 2 && sudo /usr/bin/systemctl hibernate
  14. fi
  15. fi