From 1e639100bdfe2ef220d7632b77cb54e7b60b9b7d Mon Sep 17 00:00:00 2001 From: Chisom Uma Date: Fri, 27 Mar 2026 09:19:34 +0000 Subject: [PATCH] feat: Assigning hotkeys to actions and quicklinks --- src/app/tile.rs | 1 + src/app/tile/elm.rs | 10 ++++++++++ src/app/tile/update.rs | 4 ++++ src/config.rs | 9 +++++---- src/main.rs | 11 +++++++++-- 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/app/tile.rs b/src/app/tile.rs index ef5b62b..4f96eea 100644 --- a/src/app/tile.rs +++ b/src/app/tile.rs @@ -179,6 +179,7 @@ pub struct Tile { pub struct Hotkeys { pub toggle: HotKey, pub clipboard_hotkey: HotKey, + pub shells: HashMap, } impl Tile { diff --git a/src/app/tile/elm.rs b/src/app/tile/elm.rs index a64bea8..5fc386d 100644 --- a/src/app/tile/elm.rs +++ b/src/app/tile/elm.rs @@ -60,12 +60,22 @@ pub fn new(hotkey: HotKey, config: &Config) -> (Tile, Task) { options.par_sort_by_key(|x| x.display_name.len()); let options = AppIndex::from_apps(options); + let mut shells_map = HashMap::new(); + for shell in &config.shells { + if let Some(hk_str) = &shell.hotkey + && let Ok(hk) = hk_str.parse::() + { + shells_map.insert(hk.id, shell.command.clone()); + } + } + let hotkeys = Hotkeys { toggle: hotkey, clipboard_hotkey: config .clipboard_hotkey .parse() .unwrap_or("SUPER+SHIFT+C".parse().unwrap()), + shells: shells_map, }; let home = std::env::var("HOME").unwrap_or("/".to_string()); diff --git a/src/app/tile/update.rs b/src/app/tile/update.rs index c1ccdff..a5c1ace 100644 --- a/src/app/tile/update.rs +++ b/src/app/tile/update.rs @@ -284,6 +284,10 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task { } Message::KeyPressed(hk_id) => { + if let Some(cmd) = tile.hotkeys.shells.get(&hk_id) { + return Task::done(Message::RunFunction(Function::RunShellCommand(cmd.clone()))); + } + let is_clipboard_hotkey = tile.hotkeys.clipboard_hotkey.id == hk_id; let is_open_hotkey = hk_id == tile.hotkeys.toggle.id; diff --git a/src/config.rs b/src/config.rs index 7126f0c..eb1fc05 100644 --- a/src/config.rs +++ b/src/config.rs @@ -180,10 +180,11 @@ impl Default for Buffer { /// Alias is the text that is used to call this command / search for it #[derive(Debug, Clone, Deserialize, Serialize, PartialEq)] pub struct Shelly { - command: String, - icon_path: Option, - alias: String, - alias_lc: String, + pub command: String, + pub icon_path: Option, + pub alias: String, + pub alias_lc: String, + pub hotkey: Option, } impl ToApp for Shelly { diff --git a/src/main.rs b/src/main.rs index cf1adbc..5497ea2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -76,11 +76,18 @@ fn main() -> iced::Result { .parse() .unwrap_or("SUPER+SHIFT+C".parse().unwrap()); - let hotkeys = vec![show_hide, cbhist]; + let mut hotkeys = vec![show_hide, cbhist]; + for shell in &config.shells { + if let Some(hk_str) = &shell.hotkey + && let Ok(hk) = hk_str.parse::() + { + hotkeys.push(hk); + } + } manager .register_all(&hotkeys) - .expect("Unable to register hotkey"); + .expect("Unable to register hotkeys"); info!("Hotkeys loaded"); info!("Starting rustcast");