From 500b880b978fd1d2b25a623e395231ed15ac70dc Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 7 Dec 2019 20:48:49 -0800 Subject: [PATCH] load config from executable dir first on Windows This is to support the portable-tools use case for roaming admins. Refs: https://github.com/wez/wezterm/issues/73 --- src/config/mod.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index bcdabbecb..4f743e084 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -402,15 +402,31 @@ impl Config { // specific config directories, but only returns one of them, not // multiple. In addition, it spawns a lot of subprocesses, // so we do this bit "by-hand" - let paths = [ + let mut paths = vec![ HOME_DIR .join(".config") .join("wezterm") .join("wezterm.toml"), HOME_DIR.join(".wezterm.toml"), ]; + if cfg!(windows) { + // On Windows, a common use case is to maintain a thumb drive + // with a set of portable tools that don't need to be installed + // to run on a target system. In that scenario, the user would + // like to run with the config from their thumbdrive because + // either the target system won't have any config, or will have + // the config of another user. + // So we prioritize that here: if there is a config in the same + // dir as the executable that will take precedence. + if let Ok(exe_name) = std::env::current_exe() { + if let Some(exe_dir) = exe_name.parent() { + paths.insert(0, exe_dir.join("wezterm.toml")); + } + } + } for p in &paths { + log::trace!("consider config: {}", p.display()); let mut file = match fs::File::open(p) { Ok(file) => file, Err(err) => match err.kind() {