diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-06-29 12:14:19 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-06-29 12:14:19 +0300 |
| commit | a1ea786ce911c3a41eb4e0f56e63d548a7521b09 (patch) | |
| tree | c36aa2ef65f0e759f5a7777221a029889bb78872 /battery-status.sh | |
| parent | 2ddecd462c293ab81787ee0ac2daf4dbe44e40cd (diff) | |
| download | dotfiles-a1ea786ce911c3a41eb4e0f56e63d548a7521b09.tar dotfiles-a1ea786ce911c3a41eb4e0f56e63d548a7521b09.tar.gz dotfiles-a1ea786ce911c3a41eb4e0f56e63d548a7521b09.zip | |
Added a battery status information script
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 |
