Last active
May 9, 2016 05:54
-
-
Save neerajvashistha/28351ddd07c9cc9761a0bacb03bc933d 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