moonarch/defaults/bin/moonarch-waybar-gpustat
nevaforget 5d2ce00455 Initial commit: Moonarch reproduzierbares Arch-Linux-Setup
Niri-basierter Wayland-Desktop mit greetd/regreet, Catppuccin Mocha
Theming, Rofi-Menus, Waybar und vollstaendiger Post-Install-Automatisierung.

Archinstall-Config klont das Repo automatisch via custom-commands,
danach genuegt ein einzelner Befehl fuer die komplette Einrichtung.
2026-03-23 17:42:26 +01:00

39 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/bash
# ABOUTME: Waybar-Modul das die GPU-Auslastung als JSON ausgibt.
# ABOUTME: Wird von der Waybar custom/gpu-usage Config referenziert.
while :
do
GPU_STAT=$(cat /sys/class/hwmon/hwmon5/device/gpu_busy_percent 2>/dev/null || echo "0")
ICON="<span color='#69ff94' size='8pt' rise='1.5pt'>▁</span>"
if [ "$GPU_STAT" -lt 10 ]; then
ICON="<span color='#69ff94' size='8pt' rise='1.5pt'>▁</span>"
elif [ "$GPU_STAT" -lt 20 ]; then
ICON="<span color='#2aa9ff' size='8pt' rise='1.5pt'>▂</span>"
elif [ "$GPU_STAT" -lt 40 ]; then
ICON="<span color='#f8f8f2' size='8pt' rise='1.5pt'>▃</span>"
elif [ "$GPU_STAT" -lt 50 ]; then
ICON="<span color='#f8f8f2' size='8pt' rise='1.5pt'>▄</span>"
elif [ "$GPU_STAT" -lt 60 ]; then
ICON="<span color='#ffffa5' size='8pt' rise='1.5pt'>▅</span>"
elif [ "$GPU_STAT" -lt 70 ]; then
ICON="<span color='#ffffa5' size='8pt' rise='1.5pt'>▆</span>"
elif [ "$GPU_STAT" -lt 80 ]; then
ICON="<span color='#ff9977' size='8pt' rise='1.5pt'>▇</span>"
elif [ "$GPU_STAT" -lt 100 ]; then
ICON="<span color='#dd532e' size='8pt' rise='1.5pt'>█</span>"
fi
s="text|alt|tooltip|class|percentage
GPU $ICON|GPU $ICON $GPU_STAT%|GPU $ICON $GPU_STAT%|gpustat|$GPU_STAT"
jq --unbuffered --compact-output -Rn '
( input | split("|") ) as $keys |
( inputs | split("|") ) as $vals |
[[$keys, $vals] | transpose[] | {key:.[0],value:.[1]}] | from_entries
' <<<"$s"
sleep 5
done