#!/usr/bin/env bash set -euo pipefail # Find battery + AC device (works on most laptops) BAT="$(ls -1 /sys/class/power_supply 2>/dev/null | grep -E '^BAT|^CMB|^BATT' | head -n1 || true)" AC="$(ls -1 /sys/class/power_supply 2>/dev/null | grep -E '^AC|^ADP|^ACAD' | head -n1 || true)" if [[ -z "${BAT}" ]]; then echo " --%" # unknown exit 0 fi BAT_PATH="/sys/class/power_supply/${BAT}" STATUS="$(<"${BAT_PATH}/status")" # Charging|Discharging|Full|Not charging|Unknown CAPACITY="$(<"${BAT_PATH}/capacity")" # 0-100 #  0-10,  11-35,  36-60,  61-85,  86-100 if ((CAPACITY <= 10)); then if [[ "${STATUS}" == "Charging" ]]; then ICON="󰢜 " else ICON="󰁺 " fi elif ((CAPACITY <= 30)); then if [[ "${STATUS}" == "Charging" ]]; then ICON="󰂇 " else ICON="󰁼 " fi elif ((CAPACITY <= 60)); then if [[ "${STATUS}" == "Charging" ]]; then ICON="󰂉 " else ICON="󰁿 " fi elif ((CAPACITY <= 80)); then if [[ "${STATUS}" == "Charging" ]]; then ICON="󰂊 " else ICON="󰂁 " fi else if [[ "${STATUS}" == "Charging" ]]; then ICON="󰂅 " else ICON="󰁹 " fi fi # If full, show a nicer indicator if [[ "${STATUS}" == "Full" ]]; then CHG_IND=" " # nf-fa-check fi echo "${ICON} ${CAPACITY}%"