#!/bin/bash battery_notify () { if [ ${__bat_per} -eq $1 ] && ! grep -q $1 "/tmp/battery.tmp" && [[ ${__bat_power} = $2 ]]; then notify-send -u critical -i battery-low "$3" echo $1 >> /tmp/battery.tmp fi } if command -v upower > /dev/null 2>&1 ; then __bat_power=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep state | awk '{print $2}') if [[ -n ${__bat_per} ]]; then exit fi __bat_power_ind="" if [[ ${__bat_power} = "charging" ]]; then __bat_power_ind="" elif [[ ${__bat_power} = "discharging" ]]; then __bat_power_ind="" elif [[ ${__bat_power} = "fully-charged" ]]; then __bat_power_ind="" fi __bat_per=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep percentage | awk '{print $2}' | sed "s|%||g") __time_empt=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep "time to empty" | awk '{print $4 $5}' | grep -o '^[0-9.]*[a-z]') __time_full=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep "time to full" | awk '{print $4 $5}' | grep -o '^[0-9.]*[a-z]') echo -n " ${__bat_power_ind} ${__bat_per}%" if [[ ${__bat_power} = "discharging" ]]; then echo " ${__time_empt}" else echo " ${__time_full}" fi if [ ! -f "/tmp/battery.tmp" ]; then touch /tmp/battery.tmp fi battery_notify 100 'fully-charged' 'Battery charged!' battery_notify 15 'discharging' 'Battery low (15%)!' battery_notify 10 'discharging' 'Battery lower (10%)!!' battery_notify 5 'discharging' 'Battery critical (5%)!!!' fi