Skip to content

Instantly share code, notes, and snippets.

@cpebble
Created January 30, 2018 10:14
Show Gist options
  • Save cpebble/a6e333dbf5fe6eba908e3028d984ef4a to your computer and use it in GitHub Desktop.
Save cpebble/a6e333dbf5fe6eba908e3028d984ef4a to your computer and use it in GitHub Desktop.
#!/bin/bash
#$1 is low percent
#$2 is min percent
# Original script: github.com/mrcpj1998
# MIT License
# Batpercent script sourced from private github.com/chregon2001
lockFile="/tmp/batman.lck"
export BATMAN=true
hasWarned=1
if [ -f $lockFile ];
then
exit 1
fi
touch $lockFile
while $BATMAN
do
echo $BATMAN
bat="$(batpercent)"
if (( $bat < $1 )) && (( $bat > $2 )); then
if (($hasWarned)); then
i3-nagbar -m "Battery is getting low" -b "hibernate" "systemctl hibernate" -b "sleep" "systemctl hybrid-sleep" &
echo "Battery is getting low"
notify-send "Battery warning" "Battery is getting low, save your work or connect a charger" -i battery-caution
hasWarned=0
fi
elif (($bat < $2)); then
ac_adapter=$(acpi -a | cut -d' ' -f3 | cut -d- -f1)
if [ "$ac_adapter" = "on" ]; then
notify-send "AC Adapter" "The battery is low but ac-adapter has been connected"
else
systemctl hibernate
fi
else
hasWarned=1
fi
# echo $bat
sleep 60
done
rm $lockfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment