#!/bin/bash # NVIDIA GPU load and temperature for xmobar, e.g. " 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 '%s' "$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")"