#!/bin/sh # Prints all batteries, their percentage remaining and an emoji corresponding # to charge status (🔌 for plugged up, 🔋 for discharging on battery, etc.). # Loop through all attached batteries and format the info for battery in /sys/class/power_supply/BAT?*; do # If non-first battery, print a space separator. [ -n "${capacity+x}" ] && printf " " #capacity-level capacity="$(cat "$battery/capacity" 2>&1)" if [ "$capacity" -ge 75 ] && [ "$capacity" -le 100 ] then capacity_lvl=" " elif [ "$capacity" -ge 51 ] && [ "$capacity" -le 75 ] then capacity_lvl=" " elif [ "$capacity" -ge 25 ] && [ "$capacity" -le 50 ] then capacity_lvl=" " else capacity_lvl=" " fi # Sets up the status and capacity case "$(cat "$battery/status" 2>&1)" in "Full") status="" ;; # "Discharging") status="$capacity-level" ;; "Discharging") status="$capacity_lvl" ;; "Charging") status=" " ;; "Not charging") status="🛑" ;; "Unknown") status="🟢" ;; *) exit 1 ;; esac # Will make a warn variable if discharging and low [ "$status" = "🔋" ] && [ "$capacity" -le 25 ] && warn="❗" && dunstify "Critical Battery" "Charge Immediately" -u critical -i battery-quarter #parse json file in future and close the persistent Critical Battery notification [ "$status" = "🔌" ] && [ "$capacity" -le 25 ] && [ "$warn" = "❗" ] && [ $(dunsctl count displayed) == 1 ] && dunstctl close # Prints the info printf "%s%s%d%%" "$status" "$warn" "$capacity"; unset warn done && printf "\\n"