@@ -58,9 +58,11 @@ fn dbg(msg: &str) {
5858pub struct Swapper < ' a > {
5959 executor : Box < & ' a mut dyn Executor > ,
6060 dir : String ,
61- command : String ,
62- upcase_command : String ,
63- multi_command : String ,
61+ main_action : String ,
62+ shift_action : String ,
63+ ctrl_action : String ,
64+ alt_action : String ,
65+ multi_action : String ,
6466 osc52 : bool ,
6567 active_pane_id : Option < String > ,
6668 active_pane_height : Option < i32 > ,
@@ -75,9 +77,11 @@ impl<'a> Swapper<'a> {
7577 fn new (
7678 executor : Box < & ' a mut dyn Executor > ,
7779 dir : String ,
78- command : String ,
79- upcase_command : String ,
80- multi_command : String ,
80+ main_action : String ,
81+ shift_action : String ,
82+ ctrl_action : String ,
83+ alt_action : String ,
84+ multi_action : String ,
8185 osc52 : bool ,
8286 ) -> Swapper {
8387 let since_the_epoch = SystemTime :: now ( )
@@ -88,9 +92,11 @@ impl<'a> Swapper<'a> {
8892 Swapper {
8993 executor,
9094 dir,
91- command,
92- upcase_command,
93- multi_command,
95+ main_action,
96+ shift_action,
97+ ctrl_action,
98+ alt_action,
99+ multi_action,
94100 osc52,
95101 active_pane_id : None ,
96102 active_pane_height : None ,
@@ -215,7 +221,7 @@ impl<'a> Swapper<'a> {
215221 } ;
216222
217223 let pane_command = format ! (
218- "tmux capture-pane -t {active_pane_id} -p{scroll_params} | tail -n {height} | {dir}/target/release/thumbs -f '%U :%H' -t {tmp} {args}; tmux swap-pane -t {active_pane_id}; {zoom_command} tmux wait-for -S {signal}" ,
224+ "tmux capture-pane -t {active_pane_id} -p{scroll_params} | tail -n {height} | {dir}/target/release/thumbs -f '%K :%H' -t {tmp} {args}; tmux swap-pane -t {active_pane_id}; {zoom_command} tmux wait-for -S {signal}" ,
219225 active_pane_id = active_pane_id,
220226 scroll_params = scroll_params,
221227 height = self . active_pane_height. unwrap_or( i32 :: MAX ) ,
@@ -320,7 +326,7 @@ impl<'a> Swapper<'a> {
320326 . collect :: < Vec < & str > > ( )
321327 . join ( " " ) ;
322328
323- self . execute_final_command ( & text, & self . multi_command . clone ( ) ) ;
329+ self . execute_final_command ( & text, "MAIN" , & self . multi_action . clone ( ) ) ;
324330
325331 return ;
326332 }
@@ -330,7 +336,7 @@ impl<'a> Swapper<'a> {
330336
331337 let mut splitter = item. splitn ( 2 , ':' ) ;
332338
333- if let Some ( upcase ) = splitter. next ( ) {
339+ if let Some ( modkey ) = splitter. next ( ) {
334340 if let Some ( text) = splitter. next ( ) {
335341 if self . osc52 {
336342 let base64_text = base64:: encode ( text. as_bytes ( ) ) ;
@@ -360,10 +366,13 @@ impl<'a> Swapper<'a> {
360366 std:: io:: stdout ( ) . flush ( ) . unwrap ( ) ;
361367 }
362368
363- let execute_command = if upcase. trim_end ( ) == "true" {
364- self . upcase_command . clone ( )
365- } else {
366- self . command . clone ( )
369+ let modkey = modkey. trim_end ( ) ;
370+
371+ let execute_command = match modkey {
372+ "SHIFT" => self . shift_action . clone ( ) ,
373+ "CTRL" => self . ctrl_action . clone ( ) ,
374+ "ALT" => self . alt_action . clone ( ) ,
375+ _ => self . main_action . clone ( ) ,
367376 } ;
368377
369378 // The command we run has two arguments:
@@ -389,19 +398,20 @@ impl<'a> Swapper<'a> {
389398 // Ideally user commands would just use "${THUMB}" to begin with rather than having any
390399 // sort of ad-hoc string splicing here at all, and then they could specify the quoting they
391400 // want, but that would break backwards compatibility.
392- self . execute_final_command ( text. trim_end ( ) , & execute_command) ;
401+ self . execute_final_command ( text. trim_end ( ) , modkey , & execute_command) ;
393402 }
394403 }
395404 }
396405
397- pub fn execute_final_command ( & mut self , text : & str , execute_command : & str ) {
406+ pub fn execute_final_command ( & mut self , text : & str , modkey : & str , execute_command : & str ) {
398407 let final_command = str:: replace ( execute_command, "{}" , "${THUMB}" ) ;
399408 let retrieve_command = vec ! [
400409 "bash" ,
401410 "-c" ,
402- "THUMB=\" $1\" ; eval \" $2 \" " ,
411+ "THUMB=\" $1\" ; MODIFIER= \" $2 \" ; eval \" $3 \" " ,
403412 "--" ,
404413 text,
414+ modkey,
405415 final_command. as_str( ) ,
406416 ] ;
407417
@@ -450,6 +460,8 @@ mod tests {
450460 "" . to_string ( ) ,
451461 "" . to_string ( ) ,
452462 "" . to_string ( ) ,
463+ "" . to_string ( ) ,
464+ "" . to_string ( ) ,
453465 false ,
454466 ) ;
455467
@@ -473,6 +485,8 @@ mod tests {
473485 "" . to_string ( ) ,
474486 "" . to_string ( ) ,
475487 "" . to_string ( ) ,
488+ "" . to_string ( ) ,
489+ "" . to_string ( ) ,
476490 false ,
477491 ) ;
478492
@@ -490,15 +504,19 @@ mod tests {
490504 let last_command_outputs = vec ! [ "Blah blah blah, the ignored user script output" . to_string( ) ] ;
491505 let mut executor = TestShell :: new ( last_command_outputs) ;
492506
493- let user_command = "echo \" {}\" " . to_string ( ) ;
494- let upcase_command = "open \" {}\" " . to_string ( ) ;
495- let multi_command = "open \" {}\" " . to_string ( ) ;
507+ let main_action = "echo \" {}\" " . to_string ( ) ;
508+ let shift_action = "open \" {}\" " . to_string ( ) ;
509+ let ctrl_action = "echo \" {}\" " . to_string ( ) ;
510+ let alt_action = "echo \" {}\" " . to_string ( ) ;
511+ let multi_action = "open \" {}\" " . to_string ( ) ;
496512 let mut swapper = Swapper :: new (
497513 Box :: new ( & mut executor) ,
498514 "" . to_string ( ) ,
499- user_command,
500- upcase_command,
501- multi_command,
515+ main_action,
516+ shift_action,
517+ ctrl_action,
518+ alt_action,
519+ multi_action,
502520 false ,
503521 ) ;
504522
@@ -539,21 +557,33 @@ fn app_args<'a>() -> clap::ArgMatches<'a> {
539557 . default_value ( "" ) ,
540558 )
541559 . arg (
542- Arg :: with_name ( "command " )
560+ Arg :: with_name ( "main-action " )
543561 . help ( "Command to execute after choose a hint" )
544- . long ( "command " )
562+ . long ( "main-action " )
545563 . default_value ( "tmux set-buffer -- \" {}\" && tmux display-message \" Copied {}\" " ) ,
546564 )
547565 . arg (
548- Arg :: with_name ( "upcase_command " )
549- . help ( "Command to execute after choose a hint, in upcase " )
550- . long ( "upcase-command " )
566+ Arg :: with_name ( "shift-action " )
567+ . help ( "Command to execute after choose a hint with SHIFT key pressed (Upcase) " )
568+ . long ( "shift-action " )
551569 . default_value ( "tmux set-buffer -- \" {}\" && tmux paste-buffer && tmux display-message \" Copied {}\" " ) ,
552570 )
553571 . arg (
554- Arg :: with_name ( "multi_command" )
572+ Arg :: with_name ( "ctrl-action" )
573+ . help ( "Command to execute after choose a hint with CTRL key pressed" )
574+ . long ( "ctrl-action" )
575+ . default_value ( "tmux display-message \" No CTRL action configured! Hint: {}\" " ) ,
576+ )
577+ . arg (
578+ Arg :: with_name ( "alt-action" )
579+ . help ( "Command to execute after choose a hint with ALT key pressed" )
580+ . long ( "alt-action" )
581+ . default_value ( "tmux display-message \" No ALT action configured! Hint: {}\" && echo \" FOO $MODIFIER ~ $HINT BAR\" > /tmp/tx.txt" ) ,
582+ )
583+ . arg (
584+ Arg :: with_name ( "multi-action" )
555585 . help ( "Command to execute after choose multiple hints" )
556- . long ( "multi-command " )
586+ . long ( "multi-action " )
557587 . default_value ( "tmux set-buffer -- \" {}\" && tmux paste-buffer && tmux display-message \" Multi copied {}\" " ) ,
558588 )
559589 . arg (
@@ -568,9 +598,11 @@ fn app_args<'a>() -> clap::ArgMatches<'a> {
568598fn main ( ) -> std:: io:: Result < ( ) > {
569599 let args = app_args ( ) ;
570600 let dir = args. value_of ( "dir" ) . unwrap ( ) ;
571- let command = args. value_of ( "command" ) . unwrap ( ) ;
572- let upcase_command = args. value_of ( "upcase_command" ) . unwrap ( ) ;
573- let multi_command = args. value_of ( "multi_command" ) . unwrap ( ) ;
601+ let main_action = args. value_of ( "main-action" ) . unwrap ( ) ;
602+ let shift_action = args. value_of ( "shift-action" ) . unwrap ( ) ;
603+ let ctrl_action = args. value_of ( "ctrl-action" ) . unwrap ( ) ;
604+ let alt_action = args. value_of ( "alt-action" ) . unwrap ( ) ;
605+ let multi_action = args. value_of ( "multi-action" ) . unwrap ( ) ;
574606 let osc52 = args. is_present ( "osc52" ) ;
575607
576608 if dir. is_empty ( ) {
@@ -581,9 +613,11 @@ fn main() -> std::io::Result<()> {
581613 let mut swapper = Swapper :: new (
582614 Box :: new ( & mut executor) ,
583615 dir. to_string ( ) ,
584- command. to_string ( ) ,
585- upcase_command. to_string ( ) ,
586- multi_command. to_string ( ) ,
616+ main_action. to_string ( ) ,
617+ shift_action. to_string ( ) ,
618+ ctrl_action. to_string ( ) ,
619+ alt_action. to_string ( ) ,
620+ multi_action. to_string ( ) ,
587621 osc52,
588622 ) ;
589623
0 commit comments