Created
October 15, 2020 10:49
-
-
Save yogen-p/b1c91a3d51929e3329796cb03271f513 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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