-
Notifications
You must be signed in to change notification settings - Fork 1
/
dirs.go
38 lines (32 loc) · 897 Bytes
/
dirs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package desktop
import (
"os"
"path"
"path/filepath"
"strings"
)
// DataDirs returns a slice of directories where desktop entries are stored.
func DataDirs() []string {
var dataDirs []string
homeDir := os.Getenv("HOME")
if strings.TrimSpace(homeDir) == "" {
homeDir = "~/"
}
dataHomeSetting := os.Getenv("XDG_DATA_HOME")
if dataHomeSetting == "" {
dataHomeSetting = path.Join(homeDir, ".local/share")
}
dataDirs = append(dataDirs, filepath.Join(dataHomeSetting, "applications"))
dataDirsSetting := strings.Split(os.Getenv("XDG_DATA_DIRS"), ":")
for _, dataDir := range dataDirsSetting {
dataDir = strings.TrimSpace(dataDir)
if dataDir == "" {
continue
}
dataDirs = append(dataDirs, filepath.Join(dataDir, "applications"))
}
if len(dataDirs) == 1 {
dataDirs = append(dataDirs, "/usr/local/share/applications", "/usr/share/applications")
}
return dataDirs
}