PaganOS Luna 0.6.0
PL EN DE
🔒 Repository is read-only – file editing is disabled.

recipes/gui/pagan-xfce-panel-layout/genmon-ram.sh main

27 lines Raw ← Back
123456789101112131415161718192021222324252627
#!/bin/sh
# Pagan-Flat – widget panelu XFCE (xfce4-genmon-plugin): pamięć RAM.
#
# Czyta /proc/meminfo bezpośrednio (bez procps) i wypisuje XML dla genmon.
# Użycie = MemTotal - MemAvailable (MemAvailable jest w jądrze od 3.14 i jest
# lepszym przybliżeniem „ile jeszcze można zaalokować” niż MemFree).
#
# Całość liczy jeden proces awk – taniej niż wołać sh do dzielenia liczb.

LC_ALL=C
export LC_ALL

awk '
    /^MemTotal:/     { total = $2 }        # w kB
    /^MemAvailable:/ { avail = $2 }        # w kB
    END {
        if (total <= 0) {
            print "<icon>memory-symbolic</icon><txt>—</txt><tool>RAM: brak danych</tool>"
            exit
        }
        used = total - avail
        pct = int(used * 100 / total + 0.5)
        printf "<icon>memory-symbolic</icon><txt>%d%%</txt>", pct
        printf "<tool>RAM: %.1f / %.1f GiB (%d%%)</tool>\n",
               used / 1048576, total / 1048576, pct
    }
' /proc/meminfo