Skip to content

Instantly share code, notes, and snippets.

@vivekannan
Last active March 26, 2016 06:47
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 vivekannan/20191b674b8ba14c6fbd to your computer and use it in GitHub Desktop.
Save vivekannan/20191b674b8ba14c6fbd to your computer and use it in GitHub Desktop.
Simple BASH Script to mind battery charge level.
#!/bin/bash
if [[ $(cat /sys/class/power_supply/BAT0/status) == "Charging" ]]; then
exit
fi
charge=$(cat /sys/class/power_supply/BAT0/capacity)
icon="/usr/share/icons/HighContrast/32x32/status/battery-caution.png"
if [[ $charge < 10 ]]; then
notify-send --icon=$icon "Critically low Battery level!" "Battery level is critically low!\nShutting down in 1 minute!"
sudo shutdown -h +1
elif [[ $charge < 20 ]]; then
notify-send --icon=$icon "Low Battery level!" "Battery level is low!\nCurrent Charge: $charge %"
fi
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment