-
Notifications
You must be signed in to change notification settings - Fork 0
/
pathing.go
55 lines (42 loc) · 1014 Bytes
/
pathing.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package prefer
import (
"log"
"os"
"path/filepath"
)
var standardPaths []string
func GetStandardPaths() []string {
paths := make([]string, len(standardPaths))
copy(paths, standardPaths)
return paths
}
func init() {
pathMap := make(map[string]interface{})
wd, err := os.Getwd()
if err != nil {
log.Fatalln("Could not get current working directory.")
}
// Remove /bin if it's at the end of the cwd
// NOTE: Er, os.PathSeparator is a rune... So, here's a hack.
if len(wd) > 4 && wd[len(wd)-4:] == filepath.Join("", "bin") {
wd = wd[:len(wd)-4]
}
paths := []string{".", wd}
xdgPaths := filepath.SplitList(os.Getenv("XDG_CONFIG_DIRS"))
if len(xdgPaths) > 0 {
paths = append(paths, xdgPaths...)
}
paths = append(paths, getSystemPaths()...)
for _, path := range paths {
if path == "/" {
path = ""
}
pathMap[filepath.Join(path, "/etc")] = nil
if len(path) > 0 {
pathMap[path] = nil
}
}
for path := range pathMap {
standardPaths = append(standardPaths, path)
}
}