From 07cfe8bbba0851ff4989f6aaf082d72130cd0f5b Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Mon, 23 Nov 2020 21:37:34 +0000 Subject: Add support for '~/' in config imports This allows the configuration file imports to start with '~/' and resolve relative to the user's home directory. There is no support for '~user/' or '$HOME/' or any other shell expansion. However since paths relative to the home directory should be sufficient for everything, this provides a very simple solution without any significant drawbacks. Fixes #4157. --- alacritty/src/config/mod.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'alacritty/src') diff --git a/alacritty/src/config/mod.rs b/alacritty/src/config/mod.rs index d24e8519..f9ee3528 100644 --- a/alacritty/src/config/mod.rs +++ b/alacritty/src/config/mod.rs @@ -211,7 +211,7 @@ fn load_imports(config: &Value, config_paths: &mut Vec, recursion_limit let mut merged = Value::Null; for import in imports { - let path = match import { + let mut path = match import { Value::String(path) => PathBuf::from(path), _ => { error!( @@ -222,6 +222,11 @@ fn load_imports(config: &Value, config_paths: &mut Vec, recursion_limit }, }; + // Resolve paths relative to user's home directory. + if let (Ok(stripped), Some(home_dir)) = (path.strip_prefix("~/"), dirs::home_dir()) { + path = home_dir.join(stripped); + } + if !path.exists() { info!(target: LOG_TARGET_CONFIG, "Skipping importing config; not found:"); info!(target: LOG_TARGET_CONFIG, " {:?}", path.display()); -- cgit