feat(eww): add config

This commit is contained in:
2026-03-12 17:42:32 +01:00
parent adeb93bd24
commit c6eaad94ef
11 changed files with 1128 additions and 0 deletions

44
eww/scripts/battery.sh Executable file
View File

@@ -0,0 +1,44 @@
#!/usr/bin/env bash
# battery info as JSON for eww battery-popup
action="${1:-status}"
if [[ "$action" == "set-profile" ]]; then
powerprofilesctl set "$2"
( data=$(~/.config/eww/scripts/battery.sh); eww update bat="$data" ) &
exit 0
fi
bat_path=$(echo /sys/class/power_supply/BAT* 2>/dev/null | awk '{print $1}')
if [[ ! -d "$bat_path" ]]; then
jq -nc '{capacity:0,status:"No battery",power:"0",time:"",cycles:0,profile:"unknown"}'
exit 0
fi
capacity=$(cat "$bat_path/capacity" 2>/dev/null || echo 0)
status=$(cat "$bat_path/status" 2>/dev/null || echo "Unknown")
power_uw=$(cat "$bat_path/power_now" 2>/dev/null || echo 0)
power=$(awk -v p="$power_uw" 'BEGIN{printf "%.1f", p/1000000}')
cycles=$(cat "$bat_path/cycle_count" 2>/dev/null || echo 0)
[[ "$cycles" =~ ^[0-9]+$ ]] || cycles=0
bat_upower=$(upower -e 2>/dev/null | grep BAT | head -1)
time_str=""
if [[ -n "$bat_upower" ]]; then
time_str=$(upower -i "$bat_upower" 2>/dev/null | awk '/time to/{print $4, $5}')
fi
profile=$(powerprofilesctl get 2>/dev/null || echo "unknown")
jq -nc \
--argjson capacity "$capacity" \
--arg status "$status" \
--arg power "$power" \
--arg time "$time_str" \
--argjson cycles "${cycles:-0}" \
--arg profile "$profile" \
'{$capacity,$status,$power,$time,$cycles,$profile}'