Bloggings

Back

Modified dwm-bar battery script

2025-04-23

adding battery charging nerdfont icons

This is a modification of the default dwm-battery script

#!/bin/sh

# A dwm_bar function to read the battery level and status
# GNU GPLv3

dwm_battery () {
    # Change BAT1 to whatever your battery is identified as. Typically BAT0 or BAT1
    CHARGE=$(cat /sys/class/power_supply/BAT0/capacity)
    STATUS=$(cat /sys/class/power_supply/BAT0/status)

    #printf "%s" "$SEP1"
    printf " %s"
    if [ "$IDENTIFIER" = "unicode" ]; then
        if [ "$STATUS" = "Charging" ]; then
           if   [ "${CHARGE}" -lt 10 ];  then ICON="󱃍󱐋"
           elif [ "${CHARGE}" -lt 20 ];  then ICON="󰁺󱐋"
           elif [ "${CHARGE}" -lt 30 ];  then ICON="󰁻󱐋"
           elif [ "${CHARGE}" -lt 40 ];  then ICON="󰁼󱐋"
           elif [ "${CHARGE}" -lt 50 ];  then ICON="󰁽󱐋"
           elif [ "${CHARGE}" -lt 60 ];  then ICON="󰁾󱐋"
           elif [ "${CHARGE}" -lt 70 ];  then ICON="󰁿󱐋"
           elif [ "${CHARGE}" -lt 80 ];  then ICON="󰂀󱐋"
           elif [ "${CHARGE}" -lt 90 ];  then ICON="󰂂󱐋"
           elif [ "${CHARGE}" -lt 100 ]; then ICON="󰁹󱐋"
           fi
        else
           if   [ "${CHARGE}" -lt 10 ];  then ICON="󱃍"
           elif [ "${CHARGE}" -lt 20 ];  then ICON="󰁺"
           elif [ "${CHARGE}" -lt 30 ];  then ICON="󰁻"
           elif [ "${CHARGE}" -lt 40 ];  then ICON="󰁼"
           elif [ "${CHARGE}" -lt 50 ];  then ICON="󰁽"
           elif [ "${CHARGE}" -lt 60 ];  then ICON="󰁾"
           elif [ "${CHARGE}" -lt 70 ];  then ICON="󰁿"
           elif [ "${CHARGE}" -lt 80 ];  then ICON="󰂀"
           elif [ "${CHARGE}" -lt 90 ];  then ICON="󰂂"
           elif [ "${CHARGE}" -lt 100 ]; then ICON="󰁹"
           fi
        fi
        printf "%s %s%% " "$ICON" "$CHARGE"
    else
        printf "BAT %s%% %s" "$CHARGE" "$STATUS"
    fi
    #printf "%s\n" "$SEP2"
}

dwm_battery

 


§