feat: update battery actions

notify when total of batteries is > 40
display battery slots
This commit is contained in:
David JULIEN 2021-09-19 12:32:33 +02:00
parent c2f0fa4e6a
commit 3cef4855a4

View File

@ -25,9 +25,9 @@ notify() { \
fi fi
[ 300 -gt $delta ] && return; [ 300 -gt $delta ] && return;
echo $now > $XDG_CONFIG_HOME/batteryupdate echo $now > $XDG_CONFIG_HOME/batteryupdate
case "$capacity" in case "$total" in
1[0-9]) notify-send -u "normal" "Battery is running low ($capacity%)" "Please plug your computer to a power source" ;; [2-3][0-9]) notify-send -u "normal" "Battery is running low ($capacity%)" "Please plug your computer to a power source" ;;
[0-9]) notify-send -u "critical" "Battery is dangerously low ($capacity%)" "Please plug your computer to a power source - <b>NOW!</b>" ;; *) notify-send -u "critical" "Battery is dangerously low ($capacity%)" "Please plug your computer to a power source - <b>NOW!</b>" ;;
esac esac
} }
@ -35,19 +35,24 @@ for bat in /sys/class/power_supply/BAT?/
do do
status="$(cat "$bat/status")" status="$(cat "$bat/status")"
capacity="$(cat "$bat/capacity")" capacity="$(cat "$bat/capacity")"
if [ "$status" = "Full" ]; then total="$(expr $total + $capacity)"
slot="$(basename $bat)"
if [ "Full" = "$status" ]; then
status=" " && capacity="FULL" status=" " && capacity="FULL"
printf " %s %s " "$status" "$capacity" && exit printf " %s:%s(%s) " "$slot" "$status" "$capacity"
elif [ "$status" = "Charging" ]; then else
status="" if [ "$status" = "Charging" ]; then
else status=""
case "$capacity" in else
100|[8-9][0-9]) status="" ;; case "$capacity" in
[6-7][0-9]) status="" ;; 100|[8-9][0-9]) status="" ;;
[4-5][0-9]) status="" ;; [6-7][0-9]) status="" ;;
[2-3][0-9]) status="" ;; [4-5][0-9]) status="" ;;
*) status="" ; notify;; [2-3][0-9]) status="" ;;
esac *) status="" ;;
fi esac
printf " %s %3d%% " "$status" "$capacity"; [ 40 -gt $total ] && notify;
fi
printf " %s:%s (%0.2d%%) " "$slot" "$status" "$capacity";
fi
done done