Merge pull request #18 from ftilde/master

Launch process in terminal emulator if required
This commit is contained in:
Gregory 2020-10-01 00:27:47 -04:00 committed by GitHub
commit 47b638fcdf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View file

@ -70,6 +70,18 @@ impl DesktopEntry {
})
.collect::<Vec<_>>();
// 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))
}
}

View file

@ -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(),
}
}
}