-
Notifications
You must be signed in to change notification settings - Fork 0
/
paths.go
64 lines (49 loc) · 1.35 KB
/
paths.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
56
57
58
59
60
61
62
63
64
package system
import (
"os"
"path/filepath"
)
func PathExists(path string) bool {
_, err := os.Stat(path)
if err == nil || !os.IsNotExist(err) {
return true
}
return false
}
func UserHomeDir() string {
// Ignore errors since we only care about Windows and *nix.
homedir, _ := os.UserHomeDir()
return homedir
}
// UserConfigDir returns the path where
// the user config files should be stored
// following XDG Base Directory Specification.
// Ref: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
func UserConfigDir() string {
baseConfigDir := os.Getenv("XDG_CONFIG_HOME")
if len(baseConfigDir) == 0 {
baseConfigDir = filepath.Join(UserHomeDir(), ".config")
}
return filepath.Join(baseConfigDir, "yolo")
}
func UserConfigFilePath() string {
return filepath.Join(UserConfigDir(), "yolo.yml")
}
func DefaultSSHDir() string {
return filepath.Join(UserHomeDir(), ".ssh")
}
func DefaultSSHDirExists() bool {
return PathExists(DefaultSSHDir())
}
func DefaultSSHConfigFilePath() string {
return filepath.Join(DefaultSSHDir(), "config")
}
func DefaultSSHConfigFileExists() bool {
return PathExists(DefaultSSHConfigFilePath())
}
func DefaultSSHKnownHostsFilePath() string {
return filepath.Join(DefaultSSHDir(), "known_hosts")
}
func DefaultSSHKnownHostsFileExists() bool {
return PathExists(DefaultSSHKnownHostsFilePath())
}