tmux-plugins.tmux-cpu/scripts/gram_total.sh
Fortyseven 564de038cf Adds gram_total and gram_used values
Fix: adds missing `gram_used` and `gram_total` interpolations

Removes errant 'i'
2024-09-30 21:47:30 -04:00

28 lines
749 B
Bash
Executable file

#!/usr/bin/env bash
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/helpers.sh
source "$CURRENT_DIR/helpers.sh"
gram_total_format="%dk"
print_gram_total() {
gram_total_format=$(get_tmux_option "@gram_total_format" "$gram_total_format")
if command_exists "nvidia-smi"; then
loads=$(cached_eval nvidia-smi | sed -nr 's/.*\s([0-9]+)MiB\s*\/\s*([0-9]+)MiB.*/\1 \2/p')
elif command_exists "cuda-smi"; then
loads=$(cached_eval cuda-smi | sed -nr 's/.*\s([0-9.]+) of ([0-9.]+) MB.*/\1 \2/p' | awk '{print $2-$1" "$2}')
else
echo "No GPU"
return
fi
echo "$loads" | awk -v format="$gram_total_format" '{total+=$2} END {printf format, total}'
}
main() {
print_gram_total
}
main "$@"