diff --git a/src/common/desktop_entry.rs b/src/common/desktop_entry.rs index 16d0fd1..2ef9fbc 100644 --- a/src/common/desktop_entry.rs +++ b/src/common/desktop_entry.rs @@ -70,6 +70,18 @@ impl DesktopEntry { }) .collect::>(); + // If the entry expects a terminal (emulator), but this process is not running in one, we + // launch a new one. + if self.term && !atty::is(atty::Stream::Stdout) { + let config = crate::config::Config::load()?; + let terminal_emulator_args = + shlex::split(&config.terminal_emulator).unwrap(); + split = terminal_emulator_args + .into_iter() + .chain(split.into_iter()) + .collect(); + } + Ok((split.remove(0), split)) } } diff --git a/src/config.rs b/src/config.rs index 161b4e7..f6413ea 100644 --- a/src/config.rs +++ b/src/config.rs @@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize}; pub struct Config { pub enable_selector: bool, pub selector: String, + pub terminal_emulator: String, } impl Default for Config { @@ -12,6 +13,7 @@ impl Default for Config { Config { enable_selector: false, selector: "rofi -dmenu -p 'Open With: '".to_owned(), + terminal_emulator: "xterm -e".to_owned(), } } }