neodotfiles/user/.config/suckless/dwmblocks/scripts/battery

29 lines
977 B
Text
Raw Normal View History

#!/bin/bash
2022-07-01 06:06:16 +00:00
# Loop through all attached batteries and format the info
2022-07-27 14:20:26 +00:00
currntpwr=$(powerprofilesctl get)
if [ "${currntpwr}" = "performance" ]; then
2022-08-17 12:39:39 +00:00
pwr="- 🔥 Performance"
2022-07-27 14:20:26 +00:00
elif [ "${currntpwr}" = "balanced" ]; then
2022-08-17 12:39:39 +00:00
pwr="- ⚖ Balanced"
2022-07-27 14:20:26 +00:00
elif [ "${currntpwr}" = "power-saver" ]; then
2022-08-17 12:39:39 +00:00
pwr="- ⏱ Power Saver"
2022-07-27 14:20:26 +00:00
fi
2022-07-01 06:06:16 +00:00
for battery in /sys/class/power_supply/BAT?*; do
# If non-first battery, print a space separator.
[ -n "${capacity+x}" ] && printf " "
# Sets up the status and capacity
case "$(cat "$battery/status" 2>&1)" in
"Full") status="⚡" ;;
"Discharging") status="🔋" ;;
"Charging") status="🔌" ;;
"Not charging") status="🔋" ;;
"Unknown") status="♻" ;;
*) exit 1 ;;
esac
capacity="$(cat "$battery/capacity" 2>&1)"
# Will make a warn variable if discharging and low
[ "$status" = "🔋" ] && [ "$capacity" -le 25 ] && warn="❗"
# Prints the info
2022-07-27 14:20:26 +00:00
printf "%s%s%d%%%s " " $status" "$warn " "$capacity " " $pwr"; unset warn
2022-07-01 06:06:16 +00:00
done && printf "\\n"