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

47 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"
for battery in /sys/class/power_supply/BAT?*; do
2023-02-06 22:22:50 +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
2022-09-27 10:47:14 +02:00
"Full") icon=""; color="$green" ;;
"Charging") icon=""; color="$cyan" ;;
"Not charging") icon=""; color="$white" ;;
"Unknown") icon=""; color="$orange" ;;
2022-09-21 21:46:27 +02:00
"Discharging")
if [ "$capacity" -le 10 ]; then
2022-09-27 10:47:14 +02:00
icon=""; color="$red"
2022-09-21 21:46:27 +02:00
elif [ "$capacity" -le 20 ]; then
2022-09-27 10:47:14 +02:00
icon=""; color="$red"
2022-09-21 21:46:27 +02:00
elif [ "$capacity" -le 30 ]; then
2022-09-27 10:47:14 +02:00
icon=""; color="$white"
2022-09-21 21:46:27 +02:00
elif [ "$capacity" -le 40 ]; then
2022-09-27 10:47:14 +02:00
icon=""; color="$white"
2022-09-21 21:46:27 +02:00
elif [ "$capacity" -le 50 ]; then
2022-09-27 10:47:14 +02:00
icon=""; color="$white"
2022-09-21 21:46:27 +02:00
elif [ "$capacity" -le 60 ]; then
2022-09-27 10:47:14 +02:00
icon=""; color="$white"
2022-09-21 21:46:27 +02:00
elif [ "$capacity" -le 70 ]; then
2022-09-27 10:47:14 +02:00
icon=""; color="$white"
2022-09-21 21:46:27 +02:00
elif [ "$capacity" -le 80 ]; then
2022-09-27 10:47:14 +02:00
icon=""; color="$white"
2022-09-21 21:46:27 +02:00
elif [ "$capacity" -le 90 ]; then
2022-09-27 10:47:14 +02:00
icon=""; color="$white"
elif [ "$capacity" -le 95 ]; then
icon=""; color="$white"
2022-09-21 21:46:27 +02:00
else
2022-09-27 10:47:14 +02:00
icon=""; color="$white"
2022-09-21 21:46:27 +02:00
fi
2022-09-27 10:47:14 +02:00
2022-09-21 21:46:27 +02:00
;;
*) exit 1 ;;
esac
2022-09-27 10:47:14 +02:00
printf "$color%s$reset %d" "$icon" "$capacity";
2022-09-21 21:46:27 +02:00
done && printf "\\n"