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

29 lines
969 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-09-14 00:44:31 +00:00
"Full") status="" ;;
2022-12-05 01:49:49 +00:00
"Discharging") status="" ;;
2022-09-14 00:44:31 +00:00
"Charging") status="" ;;
2022-11-30 17:31:15 +00:00
"Not charging") status="" ;;
2022-09-14 00:44:31 +00:00
"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-05 01:49:49 +00:00
[ "$status" = "" ] && [ "$capacity" -le 25 ] && 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"