diff --git a/Cargo.lock b/Cargo.lock index 1a8a7937..b96204f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,6 +19,7 @@ dependencies = [ "serde_json 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde_yaml 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "vte 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "xdg 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1087,6 +1088,11 @@ dependencies = [ "pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "xdg" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "xml-rs" version = "0.3.5" @@ -1228,5 +1234,6 @@ dependencies = [ "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" "checksum x11-dl 2.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4e4c7f0a7fb861a1bde4aa23bbda9509bda6b87de4d47c322f86e4c88241ebdd" +"checksum xdg 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "77b831a5ba77110f438f0ac5583aafeb087f70432998ba6b7dcb1d32185db453" "checksum xml-rs 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f2b15eed12692bd59d15e98ee7f8dc8408465b992d8ddb4d1672c24865132ec7" "checksum yaml-rust 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e66366e18dc58b46801afbf2ca7661a9f59cc8c5962c29892b6039b4f86fa992" diff --git a/Cargo.toml b/Cargo.toml index 06a1c638..3ab73116 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ vte = "0.1.2" mio = "0.6" serde_json = "*" copypasta = { path = "./copypasta" } +xdg = "2.0.0" clippy = { version = "0.0.104", optional = true } diff --git a/README.md b/README.md index 22aab2a1..83c904e5 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ many things (such as arrow keys) would not work. Although it's possible the default configuration would work on your system, you'll probably end up wanting to customize it anyhow. There is an `alacritty.yml` at the git repository root. Copy this to either -`$HOME/.alacritty.yml` or `$HOME/.config/alacritty.yml` and run Alacritty. +`$HOME/.alacritty.yml` or `$XDG_CONFIG_HOME/alacritty.yml` and run Alacritty. Many configuration options will take effect immediately upon saving changes to the config file. The only exception is the `font` and `dpi` section which 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 { let home = env::var("HOME")?; - // First path - let mut path = PathBuf::from(&home); - path.push(".config"); - path.push("alacritty.yml"); + // 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 + }); - 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), - } - } - } + Config::load_from(path) } /// Get list of colors diff --git a/src/lib.rs b/src/lib.rs index e060da04..d29204d2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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;