Skip to content

Instantly share code, notes, and snippets.

@imme5150
Created January 4, 2023 09:51
Show Gist options
  • Save imme5150/2acc71214d56a2a6aa2f5f89999daf59 to your computer and use it in GitHub Desktop.
Save imme5150/2acc71214d56a2a6aa2f5f89999daf59 to your computer and use it in GitHub Desktop.
#!/bin/bash
CHARGE_LEVEL=${1:-80}
while true
do
battery_level=`acpi -b | grep -P -o '[0-9]+(?=%)'`
if [ ! $battery_level ]; then
echo 'No battery found'
exit
else
status=`cat /sys/class/power_supply/BAT1/status`
if [ $status == "Charging" ] && [ $battery_level -ge $CHARGE_LEVEL ]; then
notify-send "Battery above ${CHARGE_LEVEL}%" "Charging: ${battery_level}%"
elif [ $status != "Charging" ]; then
notify-send "Laptop UNPLUGGED" "Charge: ${battery_level}%"
fi
fi
sleep 60 # seconds
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment