diff --git a/README.md b/README.md index 1be82b2..5ee187e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ _whkd_ is a simple hotkey daemon for Windows that reacts to input events by executing commands. -Its configuration file (`~/.config/whkdrc`) is a series of bindings which define the associations between the input events and the commands. +Its configuration file (`whkdrc`) is a series of bindings which define the associations between the input events and the commands. +By default, this file should be located in `~/.config/`, or an alternative can be set using the environment variable `WHKD_CONFIG_HOME`. The format of the configuration file (and this project itself) is heavily inspired by `skhd` and `sxhkd`. diff --git a/src/main.rs b/src/main.rs index 42c715e..8c0bf78 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ use lazy_static::lazy_static; use parking_lot::Mutex; use std::collections::HashMap; use std::io::Write; +use std::path::PathBuf; use std::process::ChildStdin; use std::process::Command; use std::process::Stdio; @@ -24,11 +25,24 @@ mod whkdrc; lazy_static! { static ref WHKDRC: Whkdrc = { - let mut home = dirs::home_dir().expect("no home directory found"); - home.push(".config"); + // config file defaults to `~/.config/whkdrc`, or `/whkdrc` + let mut home = std::env::var("WHKD_CONFIG_HOME").map_or_else( + |_| dirs::home_dir().expect("no home directory found").join(".config"), + |home_path| { + let home = PathBuf::from(&home_path); + + if home.as_path().is_dir() { + home + } else { + panic!( + "$Env:WHKD_CONFIG_HOME is set to '{}', which is not a valid directory", + home_path + ); + } + }, + ); home.push("whkdrc"); - - Whkdrc::load(&home).expect("could not load whkdrc") + Whkdrc::load(&home).expect(&format!("could not load whkdrc from {:?}", home)) }; static ref SESSION_STDIN: Mutex> = Mutex::new(None); }