7 homedir "github.com/mitchellh/go-homedir"
12 // InitConfigDir finds the configuration directory for micro according to the XDG spec.
13 // If no directory is found, it creates one.
14 func InitConfigDir(flagConfigDir string) error {
17 microHome := os.Getenv("MICRO_CONFIG_HOME")
19 // The user has not set $MICRO_CONFIG_HOME so we'll try $XDG_CONFIG_HOME
20 xdgHome := os.Getenv("XDG_CONFIG_HOME")
22 // The user has not set $XDG_CONFIG_HOME so we should act like it was set to ~/.config
23 home, err := homedir.Dir()
25 return errors.New("Error finding your home directory\nCan't load config files: " + err.Error())
27 xdgHome = home + "/.config"
30 microHome = xdgHome + "/micro"
34 if len(flagConfigDir) > 0 {
35 if _, err := os.Stat(flagConfigDir); os.IsNotExist(err) {
36 e = errors.New("Error: " + flagConfigDir + " does not exist. Defaulting to " + ConfigDir + ".")
38 ConfigDir = flagConfigDir
43 // Create micro config home directory if it does not exist
44 // This creates parent directories and does nothing if it already exists
45 err := os.MkdirAll(ConfigDir, os.ModePerm)
47 return errors.New("Error creating configuration directory: " + err.Error())