From 84c0803f777db529bc855859e8fd62949909fca5 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 6 Nov 2016 10:15:43 +1100 Subject: [PATCH] Merge #421: Fix multi gpu detection on Linux --- neofetch | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/neofetch b/neofetch index 2e403b2c..8b77b63d 100755 --- a/neofetch +++ b/neofetch @@ -968,7 +968,16 @@ getgpu() { if [ -f "/tmp/neofetch/gpu" ]; then source "/tmp/neofetch/gpu" else - gpu="$(PATH="/sbin:$PATH" lspci -mm | awk -F '\\"|\\" \\"' '/3D|VGA/ {print $3 " " $4}')" + bdf_number="$(PATH="/sbin:$PATH" lspci -k | grep -A2 'VGA' | grep -B2 'Kernel driver in use' | awk '/^\w/ {print $1}')" + + if [ -z "$bdf_number" ]; then + # Fallback if no kernel driver is in use + gpu="$(PATH="/sbin:$PATH" lspci -mm | awk -F '\\"|\\" \\"' '/3D|VGA/ {print $3 " " $4}')" + + else + # Find the currently used GPU by its BDF + gpu="$(PATH="/sbin:$PATH" lspci -mm | awk -v bdf_number="$bdf_number" -F '\\"|\\" \\"' '$0 ~ bdf_number {print $3 " " $4}')" + fi case "$gpu" in intel*) gpu="Intel Integrated Graphics" ;;