diff options
Diffstat (limited to 'nixos/scripts/get-battery')
-rwxr-xr-x | nixos/scripts/get-battery | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/nixos/scripts/get-battery b/nixos/scripts/get-battery new file mode 100755 index 0000000..fff6d19 --- /dev/null +++ b/nixos/scripts/get-battery @@ -0,0 +1,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 |