#!/bin/sh # Prints all batteries, their percentage remaining and an emoji corresponding # to charge status (🔌 for plugged up, 🔋 for discharging on battery, etc.). case $BLOCK_BUTTON in 3) notify-send "🔋 Battery module" "🔋: discharging 🛑: not charging ♻: stagnant charge 🔌: charging ⚡: charged ❗: battery very low! - Scroll to change adjust xbacklight." ;; 4) xbacklight -inc 10 ;; 5) xbacklight -dec 10 ;; 6) "$TERMINAL" -e "$EDITOR" "$0" ;; esac # acpi alternative # acpi | sed "s/Battery [0-9]: //;s/[Dd]ischarging, /🔋/;s/[Nn]ot charging, /🛑/;s/[Cc]harging, /🔌/;s/[Uu]nknown, /♻️/;s/[Ff]ull, /⚡/;s/ \(remaining\|until charged\)//"; exit # Check if battery directories are detected [ ! -e /sys/class/power_supply/BAT?* ] && echo "No battery found" && exit 1 # Defines the formatting for the info from the battery folders format() { # Will make a warn variable if discharging and low [ $(cat "$1/status") = "[Dd]ischarging" ] && [ $(cat "$1/capacity") -le 25 ] && local warn="❗ " # Sets up the status and capacity status=$(cat "$1/status") case "$status" in "Full") status="⚡ " ;; "Discharging") status="🔋 " ;; "Not charging") status="🛑 " ;; "Unknown") status="♻️/ " ;; esac capacity=$(cat "$1/capacity") # Prints the info printf "%s%s%d%%\n" "$status" "$warn" "$capacity" } # Loop through all attached batteries and format the info for battery in /sys/class/power_supply/BAT?* do format $battery done && return 0