Add gpu.sh, which reads both values from nvidia-smi and colors them like the CPU ones (load 25/75, temp 75/90), and show it between CPU and memory.
18 lines
708 B
Bash
Executable File
18 lines
708 B
Bash
Executable File
#!/bin/bash
|
|
# NVIDIA GPU load and temperature for xmobar, e.g. "<icon> 9% 68°C", colored like the CPU ones.
|
|
# Load 25/75 as MultiCpu; temperature 75/90 (GTX 1050 Ti Mobile: target 94°C, ~65°C driving the HDMI output).
|
|
|
|
color() { # value low high
|
|
if (( $1 > $3 )); then c='#ff5555'; elif (( $1 > $2 )); then c='#ffb86c'; else c='#50fa7b'; fi
|
|
printf '<fc=%s>%s</fc>' "$c" "$4"
|
|
}
|
|
|
|
icon=$'\U000f08ae'
|
|
IFS=', ' read -r load temp < <(nvidia-smi --query-gpu=utilization.gpu,temperature.gpu --format=csv,noheader,nounits 2>/dev/null)
|
|
if [[ ! $load =~ ^[0-9]+$ || ! $temp =~ ^[0-9]+$ ]]; then
|
|
echo "$icon N/A"
|
|
exit
|
|
fi
|
|
|
|
echo "$icon $(color "$load" 25 75 "$load%") $(color "$temp" 75 90 "$temp°C")"
|