Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/app/tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ pub struct Tile {
pub struct Hotkeys {
pub toggle: HotKey,
pub clipboard_hotkey: HotKey,
pub shells: HashMap<u32, String>,
}

impl Tile {
Expand Down
10 changes: 10 additions & 0 deletions src/app/tile/elm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,22 @@ pub fn new(hotkey: HotKey, config: &Config) -> (Tile, Task<Message>) {
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::<HotKey>()
{
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());
Expand Down
4 changes: 4 additions & 0 deletions src/app/tile/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
}

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;

Expand Down
9 changes: 5 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
alias: String,
alias_lc: String,
pub command: String,
pub icon_path: Option<String>,
pub alias: String,
pub alias_lc: String,
pub hotkey: Option<String>,
}

impl ToApp for Shelly {
Expand Down
11 changes: 9 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<HotKey>()
{
hotkeys.push(hk);
}
}

manager
.register_all(&hotkeys)
.expect("Unable to register hotkey");
.expect("Unable to register hotkeys");

info!("Hotkeys loaded");
info!("Starting rustcast");
Expand Down
Loading