dotfiles/.config/waybar/gpu-temp.sh

25 lines
631 B
Bash
Raw Permalink Normal View History

2023-09-26 17:12:28 +02:00
#!/bin/sh
declare -i hwmon_nr_amd=$(( $(cat -n /sys/class/hwmon/hwmon*/name | grep 'amdgpu' | grep -oP '\d+') - 1))
if (( $hwmon_nr_amd >= 0 )); then
hwmon_path="/sys/class/hwmon/hwmon$hwmon_nr_amd"
temp=$(head -c -4 "$hwmon_path/temp1_input")
elif which nvidia-smi &> /dev/null; then
temp=$(nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader,nounits)
fi
if [[ $temp -lt 45 ]]; then
class=low
elif [[ $temp -lt 70 ]]; then
class=normal
elif [[ $temp -lt 80 ]]; then
class=high
else
class=alert
fi
cat << EOF
{"text": "$temp°C", "alt": "$class", "tooltip": "$temp°C", "class": "$class", "percentage": ""}
EOF