1
0
Fork 0
dotfiles/.local/bin/statusbar/sb-battery

72 lines
1.4 KiB
Plaintext
Raw Normal View History

2022-09-21 21:46:27 +02:00
#!/bin/sh
red="\033[31m"
orange="\033[33m"
cyan="\033[36m"
green="\033[32m"
white="\033[37m"
reset="\033[0m"
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
2023-02-07 17:19:53 +01:00
pidof -x sbd-battery >/dev/null 2>&1 || 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="󰁹"
2023-02-07 17:19:53 +01:00
color="$green"
;;
"Not charging")
2024-01-15 22:25:14 +01:00
icon="󰁹"
2023-02-07 17:19:53 +01:00
color="$white"
;;
"Unknown")
2024-01-15 22:25:14 +01:00
icon="󰂑"
2023-02-07 17:19:53 +01:00
color="$orange"
;;
2024-01-15 22:25:14 +01:00
"Charging")
icon="󰂄"
color="$cyan"
;;
2023-02-07 17:19:53 +01:00
"Discharging")
if [ "$capacity" -le 10 ]; then
2024-01-15 22:25:14 +01:00
icon="󰂎"
2023-02-07 17:19:53 +01:00
color="$red"
elif [ "$capacity" -le 20 ]; then
2024-01-15 22:25:14 +01:00
icon="󰁺"
2023-02-07 17:19:53 +01:00
color="$red"
elif [ "$capacity" -le 30 ]; then
2024-01-15 22:25:14 +01:00
icon="󰁻"
2023-02-07 17:19:53 +01:00
color="$white"
elif [ "$capacity" -le 40 ]; then
2024-01-15 22:25:14 +01:00
icon="󰁼"
2023-02-07 17:19:53 +01:00
color="$white"
elif [ "$capacity" -le 50 ]; then
2024-01-15 22:25:14 +01:00
icon="󰁽"
2023-02-07 17:19:53 +01:00
color="$white"
elif [ "$capacity" -le 60 ]; then
2024-01-15 22:25:14 +01:00
icon="󰁾"
2023-02-07 17:19:53 +01:00
color="$white"
elif [ "$capacity" -le 70 ]; then
2024-01-15 22:25:14 +01:00
icon="󰁿"
2023-02-07 17:19:53 +01:00
color="$white"
elif [ "$capacity" -le 80 ]; then
2024-01-15 22:25:14 +01:00
icon="󰂀"
2023-02-07 17:19:53 +01:00
color="$white"
elif [ "$capacity" -le 90 ]; then
2024-01-15 22:25:14 +01:00
icon="󰂁"
2023-02-07 17:19:53 +01:00
color="$white"
2024-01-15 22:25:14 +01:00
elif [ "$capacity" -le 100 ]; then
icon="󰂂"
2023-02-07 17:19:53 +01:00
color="$white"
else
2024-01-15 22:25:14 +01:00
icon="󰁹"
2023-02-07 17:19:53 +01:00
color="$white"
fi
;;
*) exit 1 ;;
2022-09-21 21:46:27 +02:00
esac
printf "%b" "$color$icon$reset $capacity"
2022-09-21 21:46:27 +02:00
done && printf "\\n"