Skip to content

Instantly share code, notes, and snippets.

@imme5150
Last active January 9, 2025 03:59
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
MIN_CHARGE_LEVEL=${1:-40}
MAX_CHARGE_LEVEL=${2:-60}
while true
do
battery_level=`cat /sys/class/power_supply/BAT0/capacity`
if [ ! $battery_level ]; then
echo 'No battery found'
exit
else
status=`cat /sys/class/power_supply/BAT0/status`
if [ $status == "Charging" ] && [ $battery_level -ge $MIN_CHARGE_LEVEL ]; then
notify-send "Battery above ${MIN_CHARGE_LEVEL}%" "Charging: ${battery_level}%"
elif [ $status != "Charging" ] && [ $battery_level -le $MAX_CHARGE_LEVEL ]; 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