Skip to content

Commit

Permalink
Add a configurable location for whkdrc
Browse files Browse the repository at this point in the history
Can be set with `$ENV:WHKD_CONFIG_HOME`
  • Loading branch information
ashthespy authored and LGUG2Z committed May 8, 2023
1 parent 152b93e commit 976fe4f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
22 changes: 18 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 `<WHKD_CONFIG_HOME>/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<Option<ChildStdin>> = Mutex::new(None);
}
Expand Down

0 comments on commit 976fe4f

Please sign in to comment.