blob: f0a829f8b85fb0897472147256f8809c374926cd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
|