From 5add247d4a66b96b5110d271eda200798dd78fc5 Mon Sep 17 00:00:00 2001 From: nekohepott Date: Wed, 17 Jun 2026 04:16:26 +0300 Subject: [PATCH] fix for gpu parsing --- config.toml | 0 main.go | 51 ++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 36 insertions(+), 15 deletions(-) delete mode 100644 config.toml diff --git a/config.toml b/config.toml deleted file mode 100644 index e69de29..0000000 diff --git a/main.go b/main.go index 26d0961..897195c 100644 --- a/main.go +++ b/main.go @@ -169,39 +169,60 @@ func getCpu() string { } func getGpu() string { - out, err := exec.Command("sh", "-c", "lspci | grep -E 'VGA|3D'").Output() + out, err := exec.Command("sh", "-c", "lspci -mm | grep -E 'VGA|3D'").Output() if err != nil || len(out) == 0 { - return "Unknown or no GPU" + return "Unknown GPU" } lines := strings.Split(strings.TrimSpace(string(out)), "\n") var gpus []string for _, line := range lines { - parts := strings.Split(line, ": ") - if len(parts) > 1 { - cleaned := cleanGpuString(parts[len(parts)-1]) - if cleaned != "" { - gpus = append(gpus, cleaned) - } + re := regexp.MustCompile(`"([^"]+)"`) + matches := re.FindAllStringSubmatch(line, -1) + + if len(matches) >= 3 { + vendor := matches[1][1] + device := matches[2][1] + + cleaned := cleanGpuString(vendor + " " + device) + gpus = append(gpus, cleaned) } } if len(gpus) > 0 { return strings.Join(gpus, " / ") } - return "GPU not found" } func cleanGpuString(raw string) string { - re := regexp.MustCompile(`\[.*?]|\(.*?\)`) - res := re.ReplaceAllString(raw, "") + prettyNameRe := regexp.MustCompile(`\[(.*?)]`) + match := prettyNameRe.FindStringSubmatch(raw) - res = strings.ReplaceAll(res, "Corporation", "") - res = strings.ReplaceAll(res, "Controller", "") - res = strings.ReplaceAll(res, "VGA compatible", "") - res = strings.ReplaceAll(res, "3D", "") + res := raw + if len(match) > 1 { + vendor := "" + if strings.Contains(strings.ToLower(raw), "nvidia") { + vendor = "NVIDIA " + } + if strings.Contains(strings.ToLower(raw), "intel") { + vendor = "Intel " + } + if strings.Contains(strings.ToLower(raw), "amd") { + vendor = "AMD " + } + + res = vendor + match[1] + } + + re := regexp.MustCompile(`\(.*?\)|\[.*?]`) + res = re.ReplaceAllString(res, "") + + fluff := []string{"Corporation", "Controller", "VGA compatible", "3D", "Graphics", "Device"} + for _, word := range fluff { + res = strings.ReplaceAll(res, word, "") + } return strings.Join(strings.Fields(res), " ") }