summaryrefslogtreecommitdiff
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
parent86301856391b05047f1fd9f2e8999d61b26d982e (diff)
downloadalacritty-a105be82cf4c333ae691fe7f021fca8fe2b9788e.tar.gz
alacritty-a105be82cf4c333ae691fe7f021fca8fe2b9788e.zip
Real support for placing config in XDG_CONFIG_HOME
Resolves #35.
-rw-r--r--Cargo.lock7
-rw-r--r--Cargo.toml1
-rw-r--r--README.md2
-rw-r--r--src/config.rs32
-rw-r--r--src/lib.rs1
5 files changed, 22 insertions, 21 deletions
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]]
@@ -1088,6 +1089,11 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -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<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
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;