2022-09-21 21:46:27 +02:00
|
|
|
#!/bin/sh
|
2024-02-03 17:52:33 +01:00
|
|
|
. "$HOME/.local/libexec/statusbar/colors"
|
2024-01-17 12:37:27 +01:00
|
|
|
|
|
|
|
[ -z "$(ls /sys/class/power_supply)" ] && exit 0
|
|
|
|
|
2022-09-21 21:46:27 +02:00
|
|
|
for battery in /sys/class/power_supply/BAT?*; do
|
2024-02-01 20:16:45 +01:00
|
|
|
pidof -x sbd-battery >/dev/null 2>&1 || "$HOME/.local/libexec/daemons/sbd-battery" "$battery" >/dev/null 2>&1 &
|
2022-09-21 21:46:27 +02:00
|
|
|
[ -n "${capacity+x}" ] && printf " "
|
|
|
|
capacity="$(cat "$battery/capacity" 2>&1)"
|
|
|
|
case "$(cat "$battery/status" 2>&1)" in
|
2023-02-07 17:19:53 +01:00
|
|
|
"Full")
|
2024-01-15 22:25:14 +01:00
|
|
|
icon=""
|
2024-02-03 17:52:33 +01:00
|
|
|
color="$fggreen"
|
2023-02-07 17:19:53 +01:00
|
|
|
;;
|
|
|
|
"Not charging")
|
2024-01-15 22:25:14 +01:00
|
|
|
icon=""
|
2024-02-03 17:52:33 +01:00
|
|
|
color="$fgwhite"
|
2023-02-07 17:19:53 +01:00
|
|
|
;;
|
|
|
|
"Unknown")
|
2024-01-15 22:25:14 +01:00
|
|
|
icon=""
|
2024-02-03 17:52:33 +01:00
|
|
|
color="$fgorange"
|
2023-02-07 17:19:53 +01:00
|
|
|
;;
|
2024-01-15 22:25:14 +01:00
|
|
|
"Charging")
|
|
|
|
icon=""
|
2024-02-03 17:52:33 +01:00
|
|
|
color="$fgcyan"
|
2024-01-15 22:25:14 +01:00
|
|
|
;;
|
2023-02-07 17:19:53 +01:00
|
|
|
"Discharging")
|
|
|
|
if [ "$capacity" -le 10 ]; then
|
2024-01-15 22:25:14 +01:00
|
|
|
icon=""
|
2024-02-03 17:52:33 +01:00
|
|
|
color="$fgred"
|
2023-02-07 17:19:53 +01:00
|
|
|
elif [ "$capacity" -le 20 ]; then
|
2024-01-15 22:25:14 +01:00
|
|
|
icon=""
|
2024-02-03 17:52:33 +01:00
|
|
|
color="$fgred"
|
2023-02-07 17:19:53 +01:00
|
|
|
elif [ "$capacity" -le 30 ]; then
|
2024-01-15 22:25:14 +01:00
|
|
|
icon=""
|
2024-02-03 17:52:33 +01:00
|
|
|
color="$fgwhite"
|
2023-02-07 17:19:53 +01:00
|
|
|
elif [ "$capacity" -le 40 ]; then
|
2024-01-15 22:25:14 +01:00
|
|
|
icon=""
|
2024-02-03 17:52:33 +01:00
|
|
|
color="$fgwhite"
|
2023-02-07 17:19:53 +01:00
|
|
|
elif [ "$capacity" -le 50 ]; then
|
2024-01-15 22:25:14 +01:00
|
|
|
icon=""
|
2024-02-03 17:52:33 +01:00
|
|
|
color="$fgwhite"
|
2023-02-07 17:19:53 +01:00
|
|
|
elif [ "$capacity" -le 60 ]; then
|
2024-01-15 22:25:14 +01:00
|
|
|
icon=""
|
2024-02-03 17:52:33 +01:00
|
|
|
color="$fgwhite"
|
2023-02-07 17:19:53 +01:00
|
|
|
elif [ "$capacity" -le 70 ]; then
|
2024-01-15 22:25:14 +01:00
|
|
|
icon=""
|
2024-02-03 17:52:33 +01:00
|
|
|
color="$fgwhite"
|
2023-02-07 17:19:53 +01:00
|
|
|
elif [ "$capacity" -le 80 ]; then
|
2024-01-15 22:25:14 +01:00
|
|
|
icon=""
|
2024-02-03 17:52:33 +01:00
|
|
|
color="$fgwhite"
|
2023-02-07 17:19:53 +01:00
|
|
|
elif [ "$capacity" -le 90 ]; then
|
2024-01-15 22:25:14 +01:00
|
|
|
icon=""
|
2024-02-03 17:52:33 +01:00
|
|
|
color="$fgwhite"
|
2024-01-15 22:25:14 +01:00
|
|
|
elif [ "$capacity" -le 100 ]; then
|
|
|
|
icon=""
|
2024-02-03 17:52:33 +01:00
|
|
|
color="$fgwhite"
|
2023-02-07 17:19:53 +01:00
|
|
|
else
|
2024-01-15 22:25:14 +01:00
|
|
|
icon=""
|
2024-02-03 17:52:33 +01:00
|
|
|
color="$fgwhite"
|
2023-02-07 17:19:53 +01:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*) exit 1 ;;
|
2022-09-21 21:46:27 +02:00
|
|
|
esac
|
2024-02-03 17:52:33 +01:00
|
|
|
printf "%b" "<span $color>$icon</span> $capacity"
|
2022-09-21 21:46:27 +02:00
|
|
|
done && printf "\\n"
|