~kris/dots

srice

ref: e98f3b030dc24445bd55c68d95d2d81933fd68b3 srice/.local/bin/statusbar/sb-systemstats -rw-r--r-- 1.5 KiB
e98f3b03 — Kris Yotam chore: sync local state after restore (push updates, no pull) a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env bash

# System stats: GPU temp, CPU temp, memory usage (BreadOnPenguins style)
# Nerd Font icons, color-coded temps, click for details

CPU_TEMP=$(sensors | awk '
    /^Package id|^Core 0|^Tdie|^CPU/ {
        gsub(/[+°C]/, "");
        for (i=1; i<=NF; i++) {
            if ($i ~ /^[0-9]+(\.[0-9]+)?$/) {
                gsub(/\..*/, "", $i);
                print $i;
                exit;
            }
        }
    }')
[ -z "$CPU_TEMP" ] && CPU_TEMP="N/A"

# AMD GPU (edge/junction)
GPU_TEMP=$(sensors | awk '/^edge|^junction/ {gsub(/\+/,""); gsub(/\..*/,"",$2); print $2; exit}')
# NVIDIA fallback
if [ -z "$GPU_TEMP" ] && command -v nvidia-smi >/dev/null 2>&1; then
    GPU_TEMP=$(nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader)
fi
[ -z "$GPU_TEMP" ] && GPU_TEMP="N/A"

MEM_USE=$(free -m | awk '/^Mem/ {printf "%.1f", ($3)/1024}')

# CPU icon based on temp
case $CPU_TEMP in
    "N/A") CPU_ICON="󰍛 ?" ;;
    [7-9][6-9]|[8-9][0-9]|100) CPU_ICON="" ;;
    [6][6-9]|7[0-5]) CPU_ICON="󰍛" ;;
    *) CPU_ICON="󰍛" ;;
esac

# GPU icon based on temp
case $GPU_TEMP in
    "N/A") GPU_ICON="󰢮 ?" ;;
    [7-9][1-9]|[8-9][0-9]|100) GPU_ICON="" ;;
    [5][1-9]|70) GPU_ICON="󰢮" ;;
    *) GPU_ICON="󰢮" ;;
esac

echo "$GPU_ICON ${GPU_TEMP}° $CPU_ICON ${CPU_TEMP}°  ${MEM_USE}g"

case $BLOCK_BUTTON in
    1) setsid -w -f "$TERMINAL" -e htop ;;
    3) notify-send "󰍛 System Stats" "CPU: ${CPU_TEMP}°C\nGPU: ${GPU_TEMP}°C\nRAM: ${MEM_USE} GB" ;;
    6) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;;
esac