Skip to content

Instantly share code, notes, and snippets.

@yogen-p
Created October 15, 2020 10:49
Show Gist options
  • Save yogen-p/b1c91a3d51929e3329796cb03271f513 to your computer and use it in GitHub Desktop.
Save yogen-p/b1c91a3d51929e3329796cb03271f513 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
s=$(date +%s | cut -b1-13)
while true
do
export DISPLAY=:0.0
battery_percent=$(acpi -b | grep -P -o '[0-9]+(?=%)')
if on_ac_power; then
if [ "$battery_percent" -gt 90 ]; then
s=$(date +%s | cut -b1-13)
notify-send -i notification-power-disconnected -t 6000 "Battery full." "Level: ${battery_percent}% "
fi
else
if [ "$battery_percent" -lt 30 ]; then
j=$(date +%s | cut -b1-13)
p=$(expr $j - $s)
o=$(date -d@$p -u +%H:%M:%S)
notify-send -i notification-battery-low -t 6000 "Connect to AC power." "Battery Uptime: ${o}"
s=$(date +%s | cut -b1-13)
fi
fi
sleep 120 # (3 minutes)
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment