aboutsummaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2017-01-02 20:04:46 -0800
committerJoe Wilm <joe@jwilm.com>2017-01-02 20:05:31 -0800
commita105be82cf4c333ae691fe7f021fca8fe2b9788e (patch)
treeb88479308f77d939a2681fbc717c9f032c85edce /src/config.rs
parent86301856391b05047f1fd9f2e8999d61b26d982e (diff)
downloadalacritty-a105be82cf4c333ae691fe7f021fca8fe2b9788e.tar.gz
alacritty-a105be82cf4c333ae691fe7f021fca8fe2b9788e.zip
Real support for placing config in XDG_CONFIG_HOME
Resolves #35.
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs32
1 files changed, 12 insertions, 20 deletions
diff --git a/src/config.rs b/src/config.rs
index 59b9f5ea..55e69c90 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -792,26 +792,18 @@ impl Config {
pub fn load() -> Result<Config> {
let home = env::var("HOME")?;
- // First path
- let mut path = PathBuf::from(&home);
- path.push(".config");
- path.push("alacritty.yml");
-
- match Config::load_from(path) {
- Ok(c) => Ok(c),
- Err(e) => {
- match e {
- Error::NotFound => {
- // Fallback path
- let mut alt_path = PathBuf::from(&home);
- alt_path.push(".alacritty.yml");
-
- Config::load_from(alt_path)
- },
- _ => Err(e),
- }
- }
- }
+ // Try using XDG location by default
+ let path = ::xdg::BaseDirectories::new()
+ .ok()
+ .and_then(|xdg| xdg.find_config_file("alacritty.yml"))
+ .unwrap_or_else(|| {
+ // Fallback path: $HOME/.alacritty.yml
+ let mut alt_path = PathBuf::from(&home);
+ alt_path.push(".alacritty.yml");
+ alt_path
+ });
+
+ Config::load_from(path)
}
/// Get list of colors