@@ -14,13 +14,17 @@ mod test;
1414#[ derive( Parser , Debug ) ]
1515#[ command( author, version, about, long_about = None ) ]
1616struct Args {
17- /// Command to execute when no window found.
17+ /// [DEPRECATED] Command to execute when no window found.
1818 /// If not provided, only search will be done.
19+ ///
20+ /// DEPRECATED: use `run` flag.
1921 #[ arg( short = 'e' , long, value_name = "PATH" ) ]
2022 execute_path : Option < String > ,
2123
22- /// Time to wait after executing `execute_path`.
24+ /// [DEPRECATED] Time to wait after executing `execute_path`.
2325 /// Does nothing if not execute.
26+ ///
27+ /// DEPRECATED: use `run_wait` flag.
2428 #[ arg( short = 'w' , long, value_name = "SECS" ) ]
2529 execute_wait : Option < f64 > ,
2630
@@ -73,6 +77,21 @@ struct Args {
7377 /// This will not replace your current clipboard!
7478 #[ arg( long) ]
7579 clipboard : bool ,
80+
81+ /// Use no macro when a command is ran
82+ #[ arg( long) ]
83+ no_init_macro : bool ,
84+
85+ /// Command to run when no window is found.
86+ /// If not provided, only search will be done.
87+ #[ arg( long = "run" , value_name = "CMD" ) ]
88+ run_command : Option < Vec < String > > ,
89+
90+ /// After running a command, wait for a bit before running a macro.
91+ ///
92+ /// `no-launch-macro` flag disable this entirely
93+ #[ arg( long = "run-wait" , value_name = "SECS" ) ]
94+ run_command_and_wait : Option < f64 > ,
7695}
7796
7897fn main ( ) -> Result < ( ) > {
@@ -99,13 +118,19 @@ fn main() -> Result<()> {
99118
100119 let res = focus_window ( args. all , & window_title, & window_process_name) ;
101120 let mut is_change_directory = false ;
102- match ( res, args. execute_path ) {
103- ( Err ( Error :: WindowNotFound ) , Some ( path) ) => {
104- execute_path ( path) ?;
105- if let Some ( execute_wait) = args. execute_wait {
106- sleep ( execute_wait) ;
121+ let run_command_args = args
122+ . run_command
123+ . or_else ( || args. execute_path . map ( |p| vec ! [ p] ) ) ;
124+ match ( res, run_command_args) {
125+ ( Err ( Error :: WindowNotFound ) , Some ( run_command_args) ) => {
126+ run_command ( run_command_args) ?;
127+ if let Some ( wait) = args. run_command_and_wait . or ( args. execute_wait ) {
128+ sleep ( wait) ;
107129 }
108130 focus_window ( args. all , & window_title, & window_process_name) ?;
131+ if args. no_init_macro {
132+ return Ok ( ( ) ) ;
133+ }
109134 if let Some ( project_path) = & args. project_path {
110135 let project_path = if args. wsl {
111136 Cow :: Owned ( window_path_to_wsl ( project_path) )
@@ -120,7 +145,7 @@ fn main() -> Result<()> {
120145 _ => { }
121146 }
122147
123- sleep ( 0.3 ) ;
148+ sleep ( 0.1 ) ;
124149
125150 if let Some ( file_path) = args. file_path {
126151 if is_change_directory {
@@ -147,9 +172,9 @@ fn main() -> Result<()> {
147172 Ok ( ( ) )
148173}
149174
150- fn execute_path < P : AsRef < std :: path :: Path > > ( path : P ) -> Result < ( ) > {
175+ fn run_command ( args : Vec < String > ) -> Result < ( ) > {
151176 use std:: process:: Command ;
152- Command :: new ( "cmd" ) . arg ( "/C" ) . arg ( path . as_ref ( ) ) . spawn ( ) ?;
177+ Command :: new ( "cmd" ) . arg ( "/C" ) . args ( args ) . spawn ( ) ?;
153178 Ok ( ( ) )
154179}
155180
0 commit comments