Skip to content

Commit 65c1742

Browse files
wash2jackpot51
authored andcommitted
feat: prefer cosmic-term in terminal plugin
1 parent 0616b00 commit 65c1742

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

plugins/src/terminal/mod.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,47 @@ impl App {
116116
}
117117

118118
fn detect_terminal() -> (PathBuf, &'static str) {
119+
use freedesktop_desktop_entry::DesktopEntry;
119120
use std::fs::read_link;
120121

122+
let terminal_apps: Vec<_> =
123+
freedesktop_desktop_entry::Iter::new(freedesktop_desktop_entry::default_paths())
124+
.filter_map(|path| {
125+
std::fs::read_to_string(&path).ok().and_then(|input| {
126+
DesktopEntry::decode(&path, &input).ok().and_then(|de| {
127+
if de.no_display()
128+
|| de
129+
.categories()
130+
.map(|c| c.split_terminator(';').all(|c| c != "TerminalEmulator"))
131+
.unwrap_or(true)
132+
|| de.exec().is_none()
133+
{
134+
return None;
135+
}
136+
137+
Some((de.id().to_owned(), de.exec().unwrap().to_owned()))
138+
})
139+
})
140+
})
141+
.collect();
142+
143+
for id in ["com.system76.CosmicTerm"] {
144+
for (terminal_id, exec) in &terminal_apps {
145+
if terminal_id.as_str() == id {
146+
return (PathBuf::from(exec), "-e");
147+
}
148+
}
149+
}
150+
151+
if let Some((id, exec)) = terminal_apps.first() {
152+
let arg = if id == "org.gnome.Terminal" {
153+
"--"
154+
} else {
155+
"-e"
156+
};
157+
return (PathBuf::from(exec), arg);
158+
}
159+
121160
const SYMLINK: &str = "/usr/bin/x-terminal-emulator";
122161

123162
if let Ok(found) = read_link(SYMLINK) {

0 commit comments

Comments
 (0)