Skip to content

Instantly share code, notes, and snippets.

@neerajvashistha
Last active May 9, 2016 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neerajvashistha/28351ddd07c9cc9761a0bacb03bc933d to your computer and use it in GitHub Desktop.
Save neerajvashistha/28351ddd07c9cc9761a0bacb03bc933d 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