summary refs log tree commit diff stats
path: root/config.go
blob: 1045f3d13f1bdcdd48b5f0264f0bef3125644808 (plain) (blame)
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
package main

import (
	"fmt"
	"os"
)

// configFile returns the config file for pavo. It is
// configDir/pavo.json by default but can be changed by setting
// PAVO_CONFIG_FILE environment variable. If you set this then no need
// to set PAVO_CONFIG_DIR.
func configFile() (configFile string) {
	configFile = os.Getenv("PAVO_CONFIG_FILE")

	if len(configFile) == 0 {
		configFile = fmt.Sprintf("%s/%s",
			configDir(),
			"pavo.json")
	}

	return
}

// configDir returns the config directory for pavo. First
// PAVO_CONFIG_DIR environment variable is checked, if it doesn't
// exist then XDG_CONFIG_HOME & if that is not set either then we
// assume it to be the default value which is $HOME/.config according
// to XDG Base Directory Specification.
func configDir() (configDir string) {
	configDir = os.Getenv("PAVO_CONFIG_DIR")

	if len(configDir) == 0 {
		configDir = os.Getenv("XDG_CONFIG_HOME")
	}

	if len(configDir) == 0 {
		configDir = fmt.Sprintf("%s/%s",
			os.Getenv("HOME"),
			".config")
	}

	return
}