diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 8dc8218a..158dc6e3 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -76,6 +76,26 @@ lazy_static! { static ref DATA_DIR: PathBuf = dirs::data_local_dir() .expect("there is no local data directory") .join("komorebi"); + static ref WHKD_CONFIG_DIR: PathBuf = { + std::env::var("WHKD_CONFIG_HOME").map_or_else( + |_| { + dirs::home_dir() + .expect("there is no home directory") + .join(".config") + }, + |home_path| { + let whkd_config_home = PathBuf::from(&home_path); + + assert!( + whkd_config_home.as_path().is_dir(), + "$Env:WHKD_CONFIG_HOME is set to '{}', which is not a valid directory", + whkd_config_home.to_string_lossy() + ); + + whkd_config_home + }, + ) + }; } trait AhkLibrary { @@ -1293,10 +1313,7 @@ fn main() -> Result<()> { let static_config = HOME_DIR.join("komorebi.json"); let config_pwsh = HOME_DIR.join("komorebi.ps1"); let config_ahk = HOME_DIR.join("komorebi.ahk"); - let config_whkd = dirs::home_dir() - .expect("no home dir found") - .join(".config") - .join("whkdrc"); + let config_whkd = WHKD_CONFIG_DIR.join("whkdrc"); if static_config.exists() { let config_source = std::fs::read_to_string(&static_config)?; @@ -1343,14 +1360,17 @@ fn main() -> Result<()> { } if config_whkd.exists() { - println!("Found ~/.config/whkdrc; key bindings will be loaded from here when whkd is started, and you can start it automatically using the --whkd flag\n"); + println!("Found {}; key bindings will be loaded from here when whkd is started, and you can start it automatically using the --whkd flag\n", config_whkd.to_string_lossy()); } else { println!("No ~/.config/whkdrc found; you may not be able to control komorebi with your keyboard\n"); } } else if config_pwsh.exists() { println!("Found komorebi.ps1; this file will be autoloaded by komorebi\n"); if config_whkd.exists() { - println!("Found ~/.config/whkdrc; key bindings will be loaded from here when whkd is started\n"); + println!( + "Found {}; key bindings will be loaded from here when whkd is started\n", + config_whkd.to_string_lossy() + ); } else { println!("No ~/.config/whkdrc found; you may not be able to control komorebi with your keyboard\n"); }