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

70 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
red="\e[31m"
orange="\e[33m"
cyan="\e[36m"
green="\e[32m"
white="\e[37m"
reset="\e[0m"
for battery in /sys/class/power_supply/BAT?*; do
pidof -x sbd-battery >/dev/null 2>&1 || sbd-battery "$battery" >/dev/null 2>&1 &
[ -n "${capacity+x}" ] && printf " "
capacity="$(cat "$battery/capacity" 2>&1)"
case "$(cat "$battery/status" 2>&1)" in
"Full")
icon=""
color="$green"
;;
"Charging")
icon=""
color="$cyan"
;;
"Not charging")
icon=""
color="$white"
;;
"Unknown")
icon=""
color="$orange"
;;
"Discharging")
if [ "$capacity" -le 10 ]; then
icon=""
color="$red"
elif [ "$capacity" -le 20 ]; then
icon=""
color="$red"
elif [ "$capacity" -le 30 ]; then
icon=""
color="$white"
elif [ "$capacity" -le 40 ]; then
icon=""
color="$white"
elif [ "$capacity" -le 50 ]; then
icon=""
color="$white"
elif [ "$capacity" -le 60 ]; then
icon=""
color="$white"
elif [ "$capacity" -le 70 ]; then
icon=""
color="$white"
elif [ "$capacity" -le 80 ]; then
icon=""
color="$white"
elif [ "$capacity" -le 90 ]; then
icon=""
color="$white"
elif [ "$capacity" -le 95 ]; then
icon=""
color="$white"
else
icon=""
color="$white"
fi
;;
*) exit 1 ;;
esac
printf "$color%s$reset %d" "$icon" "$capacity"
done && printf "\\n"