#!/usr/bin/env bash # Battery status for the hyprlock screen, e.g. " 18%". # Uses the first battery found under /sys/class/power_supply (BAT0/BAT1, ...); # prints nothing on desktops without a battery. set -u bat="" for b in /sys/class/power_supply/BAT*; do if [ -r "${b}/capacity" ]; then bat="${b}" break fi done [ -z "${bat}" ] && exit 0 cap="$(cat "${bat}/capacity" 2>/dev/null || echo 0)" status="$(cat "${bat}/status" 2>/dev/null || echo Unknown)" case "${status}" in Charging|Full) icon="" ;; *) if [ "${cap}" -ge 80 ]; then icon="" elif [ "${cap}" -ge 60 ]; then icon="" elif [ "${cap}" -ge 40 ]; then icon="" elif [ "${cap}" -ge 20 ]; then icon="" else icon="" fi ;; esac printf '%s %s%%' "${icon}" "${cap}"