diff --git a/Cargo.lock b/Cargo.lock index 14b8bd0..e8f578c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -175,9 +175,9 @@ checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "cc" -version = "1.2.6" +version = "1.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d6dbb628b8f8555f86d0323c2eb39e3ec81901f4b83e091db8a6a76d316a333" +checksum = "a012a0df96dd6d06ba9a1b29d6402d1a5d77c6befd2566afdc26e10603dc93d7" dependencies = [ "shlex", ] @@ -819,9 +819,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.93" +version = "2.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c786062daee0d6db1132800e623df74274a0a87322d8e183338e01b3d98d058" +checksum = "987bc0be1cdea8b10216bd06e2ca407d40b9543468fafd3ddfb02f36e77f71f3" dependencies = [ "proc-macro2", "quote", @@ -963,7 +963,7 @@ dependencies = [ [[package]] name = "whkd" -version = "0.2.4" +version = "0.2.5" dependencies = [ "active-win-pos-rs", "chumsky", diff --git a/Cargo.toml b/Cargo.toml index 57afa53..36600cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,7 @@ [package] name = "whkd" -version = "0.2.4" +version = "0.2.5" description = "A simple hotkey daemon for Windows" -categories = ["hotkey-daemon", "windows"] repository = "https://github.com/LGUG2Z/whkd" license = "MIT" edition = "2021" diff --git a/src/main.rs b/src/main.rs index 81c029e..dc06a1d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,12 +81,19 @@ impl TryFrom<&HotkeyBinding> for HkmData { type Error = WHKError; fn try_from(value: &HotkeyBinding) -> Result { - let (trigger, mods) = value.keys.split_last().unwrap(); let mut mod_keys = vec![]; - let vkey = VKey::from_keyname(trigger)?; - for m in mods { - mod_keys.push(ModKey::from_keyname(m)?); - } + + let (mod_keys, vkey) = if value.keys.len() == 1 { + (vec![], VKey::from_keyname(&value.keys[0])?) + } else { + let (trigger, mods) = value.keys.split_last().unwrap(); + let vkey = VKey::from_keyname(trigger)?; + for m in mods { + mod_keys.push(ModKey::from_keyname(m)?); + } + + (mod_keys, vkey) + }; Ok(Self { mod_keys, diff --git a/src/parser.rs b/src/parser.rs index 2945f57..a6ce164 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -27,7 +27,7 @@ pub fn parser() -> impl Parser> { let hotkeys = choice((text::ident(), text::int(10))) .padded() .separated_by(just("+")) - .at_least(2) + .at_least(1) .collect::>(); let delimiter = just(":").padded(); @@ -227,4 +227,26 @@ alt + 1 : komorebic focus-workspace 0 # digits are fine in the hotkeys section assert_eq!(output.unwrap(), expected); } + + #[test] + fn test_binding_without_modkeys() { + let src = r#" +# sample comment +.shell pwsh # can be one of cmd | pwsh | powershell + +f11 : echo "hello f11""#; + + let output = parser().parse(src); + let expected = Whkdrc { + shell: Shell::Pwsh, + app_bindings: vec![], + bindings: vec![HotkeyBinding { + keys: vec![String::from("f11")], + command: String::from("echo \"hello f11\""), + process_name: None, + }], + }; + + assert_eq!(output.unwrap(), expected); + } }