40 lines
1001 B
Bash
Executable File
40 lines
1001 B
Bash
Executable File
#!/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
|