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