#!/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=" | 󰾆 PowerSaver " 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") # Calculates the percentage of remaining charge percentage="$(cat "$battery/capacity" 2>&1)" # Updates the status icon based on the battery percentage if [ "$percentage" -lt 20 ] then status=" 󰁻" elif [ "$percentage" -lt 30 ] then status=" 󰁼" elif [ "$percentage" -lt 40 ] then status=" 󰁽" elif [ "$percentage" -lt 50 ] then status=" 󰁾" elif [ "$percentage" -lt 60 ] then status=" 󰁿" elif [ "$percentage" -lt 70 ] then status=" 󰂀" elif [ "$percentage" -lt 80 ] then status=" 󰂁" elif [ "$percentage" -lt 90 ] then status=" 󰂂" fi ;; "Charging") # Calculates the percentage of remaining charge percentage="$(cat "$battery/capacity" 2>&1)" # Updates the status icon based on the battery percentage while charging if [ "$percentage" -lt 10 ] then status=" 󰢜" elif [ "$percentage" -lt 20 ] then status=" 󰂆" elif [ "$percentage" -lt 30 ] then status=" 󰂇" elif [ "$percentage" -lt 40 ] then status=" 󰂈" elif [ "$percentage" -lt 50 ] then status=" 󰢝" elif [ "$percentage" -lt 60 ] then status=" 󰂉" elif [ "$percentage" -lt 70 ] then status=" 󰢞" elif [ "$percentage" -lt 80 ] then status=" 󰂊" elif [ "$percentage" -lt 90 ] then status=" 󰂋" else status=" 󰂅" fi ;; "Not charging") status=" 󰂃" ;; "Unknown") status=" 󰂃" ;; *) exit 1 ;; esac # Will make a warn variable if discharging and low [ "$status" = " 󰁺" ] && [ "$percentage" -le 10 ] && warn="󱈸" # Prints the info printf "%s%s%d%%%s" "$status" "$warn " "$percentage" "$pwr"; unset warn done && printf "\\n"