@@ -9,7 +9,13 @@ use std::{env, fs, process::Command};
9
9
pub struct Config {
10
10
desktop_actions : bool ,
11
11
max_entries : usize ,
12
- terminal : Option < String > ,
12
+ terminal : Option < Terminal > ,
13
+ }
14
+
15
+ #[ derive( Deserialize ) ]
16
+ pub struct Terminal {
17
+ command : String ,
18
+ args : String ,
13
19
}
14
20
15
21
impl Default for Config {
@@ -29,8 +35,6 @@ pub struct State {
29
35
30
36
mod scrubber;
31
37
32
- const SENSIBLE_TERMINALS : & [ & str ] = & [ "alacritty" , "foot" , "kitty" , "wezterm" , "wterm" ] ;
33
-
34
38
#[ handler]
35
39
pub fn handler ( selection : Match , state : & State ) -> HandleResult {
36
40
let entry = state
@@ -48,18 +52,58 @@ pub fn handler(selection: Match, state: &State) -> HandleResult {
48
52
if entry. term {
49
53
match & state. config . terminal {
50
54
Some ( term) => {
51
- if let Err ( why) = Command :: new ( term) . arg ( "-e" ) . arg ( & entry. exec ) . spawn ( ) {
55
+ if let Err ( why) = Command :: new ( "sh" )
56
+ . arg ( "-c" )
57
+ . arg ( format ! (
58
+ "{} {}" ,
59
+ term. command,
60
+ term. args. replace( "{}" , & entry. exec)
61
+ ) )
62
+ . spawn ( )
63
+ {
52
64
eprintln ! ( "Error running desktop entry: {}" , why) ;
53
65
}
54
66
}
55
67
None => {
56
- for term in SENSIBLE_TERMINALS {
57
- if Command :: new ( term)
58
- . arg ( "-e" )
59
- . arg ( & entry. exec )
60
- . spawn ( )
61
- . is_ok ( )
68
+ let sensible_terminals = & [
69
+ Terminal {
70
+ command : "alacritty" . to_string ( ) ,
71
+ args : "-e {}" . to_string ( ) ,
72
+ } ,
73
+ Terminal {
74
+ command : "foot" . to_string ( ) ,
75
+ args : "-e \" {}\" " . to_string ( ) ,
76
+ } ,
77
+ Terminal {
78
+ command : "kitty" . to_string ( ) ,
79
+ args : "-e \" {}\" " . to_string ( ) ,
80
+ } ,
81
+ Terminal {
82
+ command : "wezterm" . to_string ( ) ,
83
+ args : "-e \" {}\" " . to_string ( ) ,
84
+ } ,
85
+ Terminal {
86
+ command : "wterm" . to_string ( ) ,
87
+ args : "-e \" {}\" " . to_string ( ) ,
88
+ } ,
89
+ ] ;
90
+ for term in sensible_terminals {
91
+ if Command :: new ( "which" )
92
+ . arg ( & term. command )
93
+ . output ( )
94
+ . is_ok_and ( |output| output. status . success ( ) )
62
95
{
96
+ if let Err ( why) = Command :: new ( "sh" )
97
+ . arg ( "-c" )
98
+ . arg ( format ! (
99
+ "{} {}" ,
100
+ term. command,
101
+ term. args. replace( "{}" , & entry. exec)
102
+ ) )
103
+ . spawn ( )
104
+ {
105
+ eprintln ! ( "Error running desktop entry: {}" , why) ;
106
+ }
63
107
break ;
64
108
}
65
109
}
@@ -72,13 +116,16 @@ pub fn handler(selection: Match, state: &State) -> HandleResult {
72
116
. arg ( "-c" )
73
117
. arg ( & entry. exec )
74
118
. current_dir ( if let Some ( path) = & entry. path {
75
- if path. exists ( ) { path } else { current_dir }
119
+ if path. exists ( ) {
120
+ path
121
+ } else {
122
+ current_dir
123
+ }
76
124
} else {
77
125
current_dir
78
126
} )
79
127
. spawn ( )
80
- }
81
- {
128
+ } {
82
129
eprintln ! ( "Error running desktop entry: {}" , why) ;
83
130
}
84
131
0 commit comments