Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use XDG_CONFIG_HOME if defined #232

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased

### Added

- Support for `XDG_CONFIG_HOME` will take precedence over `~/.manifoldrc` for
reading and writing the config file

## [0.15.1] - 2018-07-25

### Fixed
Expand Down
17 changes: 14 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const (
defaultHostname = "manifold.co"
defaultScheme = "https"
defaultAnalytics = true
rcFilename = ".manifoldrc"
rcFilename = "manifoldrc"
// YamlFilename is where dirprefs are stored
YamlFilename = ".manifold.yml"
)
Expand Down Expand Up @@ -122,13 +122,24 @@ func loadConfigurationCheckLegacy() (*Config, error) {
return cfg, nil
}

// RCPath returns the absolute path to the ~/.manifoldrc file
// RCPath returns the absolute path to the manifoldrc file. If XDG_CONFIG_HOME
// is defined returns $XDG_CONFIG_HOME/manifold/manifoldrc othewise it returns
// $HOME/.manifoldrc
func RCPath() (string, error) {
home := os.Getenv("XDG_CONFIG_HOME")
if home != "" {
err := os.MkdirAll(path.Join(home, "manifold"), 0700)
if err != nil {
return "", err
}
return path.Join(home, "manifold", rcFilename), nil
}

home, err := UserHome()
if err != nil {
return "", err
}
return path.Join(home, rcFilename), nil
return path.Join(home, "."+rcFilename), nil
}

// Config represents the configuration which is stored inside a ~/.manifoldrc
Expand Down