123456789101112131415161718192021222324252627282930313233343536373839 |
- #!/bin/bash -x
- #############################################
- # This is a simple battery warning script. #
- # It uses i3's nagbar to display warnings. #
- # #
- # @author agribu #
- #############################################
- # set Battery
- BATTERY=$(ls /sys/class/power_supply/ | grep '^BAT')
- # set full path
- ACPI_PATH="/sys/class/power_supply/$BATTERY"
- # get battery status
- STAT=$(cat $ACPI_PATH/status)
- # get remaining energy value
- REM=`grep "POWER_SUPPLY_CHARGE_NOW" $ACPI_PATH/uevent | cut -d= -f2`
- # get full energy value
- FULL=`grep "POWER_SUPPLY_CHARGE_FULL_DESIGN" $ACPI_PATH/uevent | cut -d= -f2`
- # get current energy value in percent
- PERCENT=`echo $(( $REM * 100 / $FULL ))`
- # set error message
- MESSAGE="AWW SNAP! I am running out of juice ... Please, charge me or I'll have to power down."
- # set energy limit in percent, where warning should be displayed
- LIMIT="10"
- # show warning if energy limit in percent is less then user set limit and
- # if battery is discharging
- if [ $PERCENT -le "$(echo $LIMIT)" ] && [ "$STAT" == "Discharging" ]; then
- DISPLAY=:0.0 /usr/bin/i3-nagbar -m "$(echo $MESSAGE)"
- fi
|