neodotfiles/user/.config/awesome/ui/widgets/battery

29 lines
988 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-09-14 00:44:31 +00:00
pwr="-  Performance"
2022-07-27 14:20:26 +00:00
elif [ "${currntpwr}" = "balanced" ]; then
2022-09-14 00:44:31 +00:00
pwr="-  Balanced"
2022-07-27 14:20:26 +00:00
elif [ "${currntpwr}" = "power-saver" ]; then
2022-09-14 00:44:31 +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
2022-12-08 03:13:08 +00:00
"Full") status=" " ;;
"Discharging") status=" " ;;
"Charging") status=" " ;;
"Not charging") status=" " ;;
"Unknown") status=" " ;;
2022-07-01 06:06:16 +00:00
*) exit 1 ;;
esac
capacity="$(cat "$battery/capacity" 2>&1)"
# Will make a warn variable if discharging and low
2022-12-08 03:13:08 +00:00
[ "$status" = " " ] && [ "$capacity" -le 100 ] && warn=""
2022-07-01 06:06:16 +00:00
# Prints the info
2022-09-14 00:44:31 +00:00
printf "%s%s%d%%%s" "$status" "$warn " "$capacity" " $pwr"; unset warn
2022-07-01 06:06:16 +00:00
done && printf "\\n"