Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions paths/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ const (

var (
// Home by default will contact the location of your home directory
Home string
Home string

// XdgConfigHome will contain $XDG_CONFIG_HOME if it exists
XdgConfigHome string
errHomeNotFound = errors.New("unable to locate home directory")
)

func init() {
// on startup set default values for Home and Config
// on startup set default values
Recalculate()
}

Expand All @@ -35,7 +38,11 @@ func init() {
// * the config file appended if we know the target is a directory
func Config(path string) string {
if path == "" {
return filepath.Join(Home, File)
if XdgConfigHome == "" {
return filepath.Join(Home, File)
}

return filepath.Join(XdgConfigHome, File)
}

expandedPath := expandPath(path)
Expand Down Expand Up @@ -66,6 +73,7 @@ func Recalculate() {
}
Home = home
}
XdgConfigHome = os.Getenv("XDG_CONFIG_HOME")
}

// IsDir tells us if the path is valid and is a directory
Expand Down
7 changes: 7 additions & 0 deletions paths/paths_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,10 @@ func TestConfig(t *testing.T) {
assert.Equal(t, tc.expectedPath, actual, tc.desc)
}
}

func TestXdgConfig(t *testing.T) {
XdgConfigHome = "/home/user/.xdg_config"

assert.Equal(t, filepath.Join(XdgConfigHome, File), Config(""))

}