Skip to content

Instantly share code, notes, and snippets.

@otsuarez
Last active December 17, 2015 17:59
Show Gist options
  • Save otsuarez/5649564 to your computer and use it in GitHub Desktop.
Save otsuarez/5649564 to your computer and use it in GitHub Desktop.
battery status reporting under i3
#!/bin/bash
# crontab -e
# */10 * * * * DISPLAY=:0.0 ${HOME}/bin/battery.sh
NOW=`echo $((100*$(sed -n "s/remaining capacity: *\(.*\) m[AW]h/\1/p" /proc/acpi/battery/BAT0/state)/$(sed -n "s/last full capacity: *\(.*\) m[AW]h/\1/p" /proc/acpi/battery/BAT0/info)))`
THRESHOLD="30"
if [ $NOW -lt $THRESHOLD ];
then
/usr/bin/i3-nagbar -m "Battery status critical (below "$THRESHOLD"%)" -b 'pm-suspend' 'sudo pm-suspend'
#notify-send "Battery status critical (below "$THRESHOLD"%)"
fi
#notify-send "Battery status: $NOW%"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment