28 lines
988 B
Bash
Executable file
28 lines
988 B
Bash
Executable file
#!/bin/bash
|
|
# Loop through all attached batteries and format the info
|
|
currntpwr=$(powerprofilesctl get)
|
|
if [ "${currntpwr}" = "performance" ]; then
|
|
pwr="- Performance"
|
|
elif [ "${currntpwr}" = "balanced" ]; then
|
|
pwr="- Balanced"
|
|
elif [ "${currntpwr}" = "power-saver" ]; then
|
|
pwr="- Power Saver"
|
|
fi
|
|
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"
|