fix for absolute paths

This commit is contained in:
nekohepott 2026-06-17 04:16:25 +03:00
parent 584d2dcd78
commit c9c617a1f0
No known key found for this signature in database

20
main.go
View File

@ -7,6 +7,7 @@ import (
_ "image/png" _ "image/png"
"os" "os"
"os/exec" "os/exec"
"path/filepath"
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
@ -44,7 +45,7 @@ func getDist() string {
return dist return dist
} }
} }
return "unknown distro :(" return "no /etc/os-release file found"
} }
func getRam() string { func getRam() string {
@ -199,6 +200,19 @@ func printLogo(path string, width uint) {
} }
} }
func getAbsLogoPath(relativePath string) string {
if _, err := os.Stat(relativePath); err == nil {
return relativePath
}
systemPath := filepath.Join("/usr/share/gogofetch", relativePath)
if _, err := os.Stat(systemPath); err == nil {
return systemPath
}
return relativePath
}
func main() { func main() {
type Info struct { type Info struct {
Label string Label string
@ -210,6 +224,8 @@ func main() {
defaultLogo = logoMap["default"] defaultLogo = logoMap["default"]
} }
absoluteDefaultLogo := getAbsLogoPath(defaultLogo)
stats := []Info{ stats := []Info{
{"dist", dist}, {"dist", dist},
{"host", getHostname()}, {"host", getHostname()},
@ -220,7 +236,7 @@ func main() {
{"pkgs", getPkgs()}, {"pkgs", getPkgs()},
} }
logoPath := flag.String("l", defaultLogo, "Absolute or relative path to the logo image") logoPath := flag.String("l", absoluteDefaultLogo, "Absolute or relative path to the logo image")
width := flag.Int("w", 200, "Logo width in lines") width := flag.Int("w", 200, "Logo width in lines")
flag.Parse() flag.Parse()
if _, err := os.Stat(*logoPath); os.IsNotExist(err) { if _, err := os.Stat(*logoPath); os.IsNotExist(err) {