#!/bin/bash

gpu_usage=$(nvidia-smi -q | grep 'Gpu' | awk '{ print $3 }')
gpu_temp=$(nvidia-smi -q | grep 'GPU Current Temp' | awk '{ print $5 }')
gpu_clock=$(nvidia-smi -q | grep 'Graphics' | head -n1 | awk '{ print $3 }')
gpu_power=$(nvidia-smi -q | grep 'Power Draw' | awk '{ print $4 }' | awk -F. '{ print $1 }')
fan_duty=$(nvidia-smi -q | grep 'Fan Speed' | awk '{ print $4 }')

vram_used=$(nvidia-smi -q | grep 'Used' | head -n1 | awk '{print $3}' | head -c4 | sed -r 's/[.]+/,/g')

# make usage human readable 
# when the usage in MiB is greater than 3 charaters, so over 1G
if [ ${#vram_used} -gt 3 ]; then
    vram_used=$(echo "$(awk "BEGIN { print "$vram_used/1024" }" | head -c4)G")
    else 
    vram_used=$(echo "$vram_used"M)
fi

vram_used_percentage=$(nvidia-smi -q | grep 'Memory' | sed '3q;d' | awk '{print $3}')
vram_size=$(nvidia-smi -q | grep 'Total' | head -n1 | awk '{print int($3/1000)}')

#echo "GPU   "$gpu_usage"%   $gpu_temp°C   "$gpu_clock"MHz   "$gpu_power"W   FAN   "$fan_duty"%   VRAM   "$vram_used_percentage"%   $vram_used" / "$vram_size"G

# echo "GPU  "$gpu_usage"%  $gpu_temp°C  "$gpu_clock"MHz  "$gpu_power"W  FAN "$fan_duty"%  VRAM "$vram_used_percentage"%  $vram_used"/"$vram_size"G
# echo ""$gpu_usage"%  $gpu_temp°C  "$gpu_clock"MHz  "$gpu_power"W  FAN "$fan_duty"%  VRAM "$vram_used_percentage"%  $vram_used"/"$vram_size"G
echo ""$gpu_usage"%  $gpu_temp°C  "$gpu_clock"MHz  "$gpu_power"W  󰈐 "$fan_duty"%  󰆼  "$vram_used_percentage"%  $vram_used"/"$vram_size"G

#
