From 24295dfd76fa0b9a1e1e34ed29bac7fc547c9e66 Mon Sep 17 00:00:00 2001 From: piotr Date: Fri, 18 Jun 2021 01:56:47 +0200 Subject: [PATCH] respect XDG_DATA_HOME --- main.go | 2 +- tools.go | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 841cfc1..22e3310 100644 --- a/main.go +++ b/main.go @@ -158,7 +158,7 @@ func main() { configDirectory = configDir() if !pathExists(filepath.Join(configDirectory, "drawer.css")) { - copyFile("/usr/share/nwg-drawer/drawer.css", filepath.Join(configDirectory, "drawer.css")) + copyFile(filepath.Join(getDataHome(), "nwg-drawer/drawer.css"), filepath.Join(configDirectory, "drawer.css")) } cacheDirectory := cacheDir() diff --git a/tools.go b/tools.go index bd8ac7f..06d39bd 100644 --- a/tools.go +++ b/tools.go @@ -202,12 +202,19 @@ func copyFile(src, dst string) error { return os.Chmod(dst, srcinfo.Mode()) } +func getDataHome() string { + if os.Getenv("XDG_DATA_HOME") != "" { + return os.Getenv("XDG_DATA_HOME") + } + return "/usr/share/" +} + func getAppDirs() []string { var dirs []string xdgDataDirs := "" home := os.Getenv("HOME") - xdgDataHome := os.Getenv("XDG_DATA_HOME") + xdgDataHome := getDataHome() if os.Getenv("XDG_DATA_DIRS") != "" { xdgDataDirs = os.Getenv("XDG_DATA_DIRS") } else { @@ -257,7 +264,7 @@ func listDesktopFiles() []string { } func setUpCategories() { - path := "/usr/share/nwg-menu/desktop-directories" + path := filepath.Join(getDataHome(), "nwg-menu/desktop-directories") var other category for _, cName := range categoryNames {