about summary refs log tree commit diff
path: root/nixos/scripts/get-battery
blob: fff6d19e830f166dd703f008eca6b9b64a3947c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/sh

BATTERY_PATH="/sys/class/power_supply/BAT0"

# Check if the battery is present
if [ -d "$BATTERY_PATH" ]; then
    # Get battery status (Charging, Discharging, Full, etc.)
    status=$(cat "$BATTERY_PATH/status")

    # Get battery percentage
    capacity=$(cat "$BATTERY_PATH/capacity")

    # Set default icon and color
    icon=""
    color=""

    # Determine icon based on battery status
    if [ "$status" == "Charging" ]; then
        icon="󱟦"  # Charging icon
    else
        icon="󱟤"  # Discharging icon
    fi

    # Determine color based on battery percentage
    if [ "$capacity" -le 20 ]; then
        color="<fc=#f38ba8>"  # Red
    elif [ "$capacity" -le 50 ]; then
        color="<fc=#fab387>"  # Orange
    elif [ "$capacity" -le 79 ]; then
        color="<fc=#f9e2af>"  # Yellow
    else
        color="<fc=#a6e3a1>"  # Green
    fi

    # Display battery information with icon and color
    echo "$color$icon $capacity%</fc>"
else
    echo "Battery not found."
fi