diff options
author | Joe Wilm <joe@jwilm.com> | 2017-01-02 20:04:46 -0800 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2017-01-02 20:05:31 -0800 |
commit | a105be82cf4c333ae691fe7f021fca8fe2b9788e (patch) | |
tree | b88479308f77d939a2681fbc717c9f032c85edce /src | |
parent | 86301856391b05047f1fd9f2e8999d61b26d982e (diff) | |
download | r-alacritty-a105be82cf4c333ae691fe7f021fca8fe2b9788e.tar.gz r-alacritty-a105be82cf4c333ae691fe7f021fca8fe2b9788e.tar.bz2 r-alacritty-a105be82cf4c333ae691fe7f021fca8fe2b9788e.zip |
Real support for placing config in XDG_CONFIG_HOME
Resolves #35.
Diffstat (limited to 'src')
-rw-r--r-- | src/config.rs | 32 | ||||
-rw-r--r-- | src/lib.rs | 1 |
2 files changed, 13 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 @@ -45,6 +45,7 @@ extern crate serde; extern crate serde_json; extern crate serde_yaml; extern crate vte; +extern crate xdg; #[macro_use] extern crate bitflags; |