@@ -3,13 +3,14 @@ use anyrun_plugin::{anyrun_interface::HandleResult, *};
3
3
use fuzzy_matcher:: FuzzyMatcher ;
4
4
use scrubber:: DesktopEntry ;
5
5
use serde:: Deserialize ;
6
- use std:: { env, fs, process:: Command } ;
6
+ use std:: { env, fs, path :: PathBuf , process:: Command } ;
7
7
8
8
#[ derive( Deserialize ) ]
9
9
pub struct Config {
10
10
desktop_actions : bool ,
11
11
max_entries : usize ,
12
12
terminal : Option < Terminal > ,
13
+ preprocess_exec_script : Option < PathBuf > ,
13
14
}
14
15
15
16
#[ derive( Deserialize ) ]
@@ -23,6 +24,7 @@ impl Default for Config {
23
24
Self {
24
25
desktop_actions : false ,
25
26
max_entries : 5 ,
27
+ preprocess_exec_script : None ,
26
28
terminal : None ,
27
29
}
28
30
}
@@ -49,6 +51,26 @@ pub fn handler(selection: Match, state: &State) -> HandleResult {
49
51
} )
50
52
. unwrap ( ) ;
51
53
54
+ let exec = if let Some ( script) = & state. config . preprocess_exec_script {
55
+ let output = Command :: new ( "sh" )
56
+ . arg ( "-c" )
57
+ . arg ( format ! (
58
+ "{} {} {}" ,
59
+ script. display( ) ,
60
+ if entry. term { "term" } else { "no-term" } ,
61
+ & entry. exec
62
+ ) )
63
+ . output ( )
64
+ . unwrap_or_else ( |why| {
65
+ eprintln ! ( "Error running preprocess script: {}" , why) ;
66
+ std:: process:: exit ( 1 ) ;
67
+ } ) ;
68
+
69
+ String :: from_utf8_lossy ( & output. stdout ) . trim ( ) . to_string ( )
70
+ } else {
71
+ entry. exec . clone ( )
72
+ } ;
73
+
52
74
if entry. term {
53
75
match & state. config . terminal {
54
76
Some ( term) => {
@@ -57,7 +79,7 @@ pub fn handler(selection: Match, state: &State) -> HandleResult {
57
79
. arg ( format ! (
58
80
"{} {}" ,
59
81
term. command,
60
- term. args. replace( "{}" , & entry . exec)
82
+ term. args. replace( "{}" , & exec)
61
83
) )
62
84
. spawn ( )
63
85
{
@@ -98,7 +120,7 @@ pub fn handler(selection: Match, state: &State) -> HandleResult {
98
120
. arg ( format ! (
99
121
"{} {}" ,
100
122
term. command,
101
- term. args. replace( "{}" , & entry . exec)
123
+ term. args. replace( "{}" , & exec)
102
124
) )
103
125
. spawn ( )
104
126
{
@@ -114,7 +136,7 @@ pub fn handler(selection: Match, state: &State) -> HandleResult {
114
136
115
137
Command :: new ( "sh" )
116
138
. arg ( "-c" )
117
- . arg ( & entry . exec )
139
+ . arg ( & exec)
118
140
. current_dir ( if let Some ( path) = & entry. path {
119
141
if path. exists ( ) {
120
142
path
0 commit comments