39 lines
1017 B
Bash
Executable File
39 lines
1017 B
Bash
Executable File
#!/bin/bash
|
|
# Battery indicator bar for waybar (JSON, class drives CSS blink animations).
|
|
# Usage: battery.sh bar
|
|
|
|
# Find first power supply with type "Battery" (works for BAT0, BAT1, CMB0, etc.)
|
|
BAT=""
|
|
for PS in /sys/class/power_supply/*; do
|
|
if [ -f "$PS/type" ] && [ "$(cat "$PS/type")" = "Battery" ]; then
|
|
BAT="$PS"
|
|
break
|
|
fi
|
|
done
|
|
|
|
case "$1" in
|
|
bar)
|
|
if [ -z "$BAT" ] || [ ! -f "$BAT/capacity" ]; then
|
|
echo '{"text": " ", "class": "", "percentage": 100}'
|
|
exit 0
|
|
fi
|
|
|
|
CAP=$(cat "$BAT/capacity")
|
|
STATUS=$(cat "$BAT/status")
|
|
|
|
CLASS=""
|
|
case "$STATUS" in
|
|
Charging) CLASS="charging" ;;
|
|
Full) CLASS="full" ;;
|
|
Discharging)
|
|
if [ "$CAP" -le 10 ]; then CLASS="critical"
|
|
elif [ "$CAP" -le 25 ]; then CLASS="warning"
|
|
else CLASS="discharging"
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
echo "{\"text\": \" \", \"class\": \"$CLASS\", \"percentage\": $CAP}"
|
|
;;
|
|
esac
|