diff --git a/plugins/applications/README.md b/plugins/applications/README.md index 5d19b1e..ab77fe4 100644 --- a/plugins/applications/README.md +++ b/plugins/applications/README.md @@ -16,5 +16,8 @@ Config( // Also show the Desktop Actions defined in the desktop files, e.g. "New Window" from LibreWolf desktop_actions: true, max_entries: 5, + // The terminal used for running terminal based desktop entries, if left as `None` a static list of terminals is used + // to determine what terminal to use. + terminal: Some("alacritty"), ) ``` \ No newline at end of file diff --git a/plugins/applications/src/lib.rs b/plugins/applications/src/lib.rs index 804f9df..f44d4c2 100644 --- a/plugins/applications/src/lib.rs +++ b/plugins/applications/src/lib.rs @@ -9,6 +9,7 @@ use std::{fs, process::Command}; pub struct Config { desktop_actions: bool, max_entries: usize, + terminal: Option, } impl Default for Config { @@ -16,6 +17,7 @@ impl Default for Config { Self { desktop_actions: false, max_entries: 5, + terminal: None, } } } @@ -27,6 +29,8 @@ pub struct State { mod scrubber; +const SENSIBLE_TERMINALS: &[&str] = &["alacritty", "foot", "kitty", "wezterm", "wterm"]; + #[handler] pub fn handler(selection: Match, state: &State) -> HandleResult { let entry = state @@ -41,8 +45,28 @@ pub fn handler(selection: Match, state: &State) -> HandleResult { }) .unwrap(); - if let Err(why) = Command::new("sh").arg("-c").arg(&entry.exec).spawn() { - println!("Error running desktop entry: {}", why); + if entry.term { + match &state.config.terminal { + Some(term) => { + if let Err(why) = Command::new(term).arg("-e").arg(&entry.exec).spawn() { + eprintln!("Error running desktop entry: {}", why); + } + } + None => { + for term in SENSIBLE_TERMINALS { + if Command::new(term) + .arg("-e") + .arg(&entry.exec) + .spawn() + .is_ok() + { + break; + } + } + } + } + } else if let Err(why) = Command::new("sh").arg("-c").arg(&entry.exec).spawn() { + eprintln!("Error running desktop entry: {}", why); } HandleResult::Close diff --git a/plugins/applications/src/scrubber.rs b/plugins/applications/src/scrubber.rs index 33131d3..625a34d 100644 --- a/plugins/applications/src/scrubber.rs +++ b/plugins/applications/src/scrubber.rs @@ -8,6 +8,7 @@ pub struct DesktopEntry { pub name: String, pub desc: Option, pub icon: String, + pub term: bool, } const FIELD_CODE_LIST: &[&str] = &[ @@ -78,6 +79,10 @@ impl DesktopEntry { .get("Icon") .unwrap_or(&"application-x-executable") .to_string(), + term: map + .get("Terminal") + .map(|val| val.to_lowercase() == "true") + .unwrap_or(false), }) } else { None @@ -119,6 +124,10 @@ impl DesktopEntry { }, desc: Some(entry.name.clone()), icon: entry.icon.clone(), + term: map + .get("Terminal") + .map(|val| val.to_lowercase() == "true") + .unwrap_or(false), }) } }