File: config.go

package info (click to toggle)
golang-github-kyoh86-xdg 1.2.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 184 kB
  • sloc: makefile: 13
file content (29 lines) | stat: -rw-r--r-- 805 bytes parent folder | download | duplicates (2)
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
package xdg

const (
	// ConfigHomeEnv is the name of the environment variable holding a user configuration directory path.
	ConfigHomeEnv = "XDG_CONFIG_HOME"
	// ConfigDirsEnv is the name of the environment variable holding system configuration directory paths.
	ConfigDirsEnv = "XDG_CONFIG_DIRS"
)

// AllConfigDirs returns all XDG configuration directories.
func AllConfigDirs() []string {
	var dirs []string

	// XDG_CONFIG_HOME
	if home := ConfigHome(); home != "" {
		dirs = append(dirs, home)
	}

	// XDG_CONFIG_DIRS
	dirs = append(dirs, ConfigDirs()...)

	return dirs
}

// FindConfigFile finds a file from the XDG configuration directory.
// If one cannot be found, an error `ErrNotFound` be returned.
func FindConfigFile(rel ...string) (string, error) {
	return findFile(AllConfigDirs(), rel)
}