diff options
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/config.rs b/src/config.rs index 4511b227..e9cd505a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -811,27 +811,40 @@ impl Config { /// /// The config file is loaded from the first file it finds in this list of paths /// - /// 1. `$HOME/.config/alacritty.yml` - /// 2. `$HOME/.alacritty.yml` + /// 1. $XDG_CONFIG_HOME/alacritty/alacritty.yml + /// 2. $XDG_CONFIG_HOME/alacritty.yml + /// 3. $HOME/.config/alacritty/alacritty.yml + /// 4. $HOME/.alacritty.yml pub fn load() -> Result<Config> { let home = env::var("HOME")?; // Try using XDG location by default - let path = ::xdg::BaseDirectories::new() + let path = ::xdg::BaseDirectories::with_prefix("alacritty") .ok() .and_then(|xdg| xdg.find_config_file("alacritty.yml")) + .or_else(|| { + ::xdg::BaseDirectories::new().ok().and_then(|fallback| { + fallback.find_config_file("alacritty.yml") + }) + }) + .or_else(|| { + // Fallback path: $HOME/.config/alacritty/alacritty.yml + let fallback = PathBuf::from(&home).join(".config/alacritty/alacritty.yml"); + match fallback.exists() { + true => Some(fallback), + false => None + } + }) .unwrap_or_else(|| { // Fallback path: $HOME/.alacritty.yml - let mut alt_path = PathBuf::from(&home); - alt_path.push(".alacritty.yml"); - alt_path + PathBuf::from(&home).join(".alacritty.yml") }); Config::load_from(path) } pub fn write_defaults() -> io::Result<PathBuf> { - let path = ::xdg::BaseDirectories::new() + let path = ::xdg::BaseDirectories::with_prefix("alacritty") .map_err(|err| io::Error::new(io::ErrorKind::NotFound, ::std::error::Error::description(&err))) .and_then(|p| p.place_config_file("alacritty.yml"))?; File::create(&path)?.write_all(DEFAULT_ALACRITTY_CONFIG.as_bytes())?; |