diff options
Diffstat (limited to 'battery-status.sh')
| -rwxr-xr-x | battery-status.sh | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/battery-status.sh b/battery-status.sh new file mode 100755 index 0000000..f0a829f --- /dev/null +++ b/battery-status.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +battery_notify () { + if [ ${__bat_per} -eq $1 ] && [[ ${__bat_power} = $2 ]] && ! [[ -f "/tmp/battery.tmp" ]]; then + notify-send -u critical -i battery-low "$3" + touch /tmp/battery.tmp + elif ! [ ${__bat_per} -eq $1 ] && [[ -f "/tmp/battery.tmp" ]]; then + rm /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 + + battery_notify 100 'fully-charged' 'Battery charged!' + battery_notify 15 'discharging' 'Battery low!' + battery_notify 10 'discharging' 'Battery lower!!' + battery_notify 5 'discharging' 'Battery critical!!!' +fi |
