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

29 lines
988 B
Text
Raw Normal View History

2022-12-20 00:15:21 +00:00
#!/bin/bash
# Loop through all attached batteries and format the info
currntpwr=$(powerprofilesctl get)
if [ "${currntpwr}" = "performance" ]; then
2023-05-26 06:32:03 +00:00
pwr=" | 󰓅 Performance "
2022-12-20 00:15:21 +00:00
elif [ "${currntpwr}" = "balanced" ]; then
2023-05-26 06:32:03 +00:00
pwr=" | 󰾅 Balanced "
2022-12-20 00:15:21 +00:00
elif [ "${currntpwr}" = "power-saver" ]; then
2023-05-26 06:32:03 +00:00
pwr=" | 󰾆 PowerSaver "
2022-12-20 00:15:21 +00:00
fi
2023-05-26 06:32:03 +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 100 ] && warn=""
# Prints the info
printf "%s%s%d%%%s" "$status" "$warn " "$capacity" "$pwr"; unset warn
done && printf "\\n"