Skip to content

Commit

Permalink
Merge pull request #130 from zquestz/updated-config-path
Browse files Browse the repository at this point in the history
Update configuration path to .config directory
  • Loading branch information
zquestz authored Jan 26, 2018
2 parents 760a08e + 1323956 commit 033b20a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Feel free to try it out at [https://jumps.io/](https://jumps.io/).

## Configuration

To setup your own default configuration just create `~/.s/config`. The configuration file is in UCL format. JSON is also fully supported as UCL can parse JSON files.
To setup your own default configuration just create `~/.config/s/config`. The configuration file is in UCL format. JSON is also fully supported as UCL can parse JSON files.

For more information about UCL visit:
[https://github.com/vstakhov/libucl](https://github.com/vstakhov/libucl)
Expand Down
19 changes: 14 additions & 5 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ type Config struct {
Whitelist []string `json:"whitelist"`
}

// Load reads the configuration from ~/.s/config and loads it into the Config struct.
// Load reads the configuration from ~/.config/s/config
// and loads it into the Config struct.
// The config is in UCL format.
func (c *Config) Load() error {
conf, err := c.loadConfig()
Expand All @@ -54,13 +55,21 @@ func (c *Config) loadConfig() ([]byte, error) {
return nil, err
}

f, err := os.Open(filepath.Join(h, ".s", "config"))
f, err := os.Open(filepath.Join(h, ".config", "s", "config"))
if err != nil {
if os.IsNotExist(err) {
return nil, nil
}
// Legacy configuration path.
f, err = os.Open(filepath.Join(h, ".s", "config"))
if err != nil {
if os.IsNotExist(err) {
return nil, nil
}

return nil, err
return nil, err
}
} else {
return nil, err
}
}
defer f.Close()

Expand Down

0 comments on commit 033b20a

Please sign in to comment.