@@ -756,6 +756,8 @@ async def remote_cli(unet, prompt, title, background):
756
756
unet .cli_sockpath = sockpath
757
757
logging .info ("server created on :\n %s\n " , sockpath )
758
758
759
+ wait_tmux = bool (os .getenv ("TMUX" , "" )) and not sys .stdin .isatty ()
760
+
759
761
# Open a new window with a new CLI
760
762
python_path = await unet .async_get_exec_path (["python3" , "python" ])
761
763
us = os .path .realpath (__file__ )
@@ -765,7 +767,25 @@ async def remote_cli(unet, prompt, title, background):
765
767
if prompt :
766
768
cmd += f" --prompt='{ prompt } '"
767
769
cmd += " " + unet .cli_sockpath
768
- unet .run_in_window (cmd , title = title , background = False )
770
+
771
+ channel = None
772
+ if wait_tmux :
773
+ from .base import Commander # pylint: disable=import-outside-toplevel
774
+
775
+ channel = "{}-{}" .format (os .getpid (), Commander .tmux_wait_gen )
776
+ logger .info ("XXX channel is %s" , channel )
777
+ # If we don't have a tty to pause on pause for tmux windows to exit
778
+ if channel is not None :
779
+ Commander .tmux_wait_gen += 1
780
+
781
+ unet .run_in_window (cmd , title = title , background = False , wait_for = channel )
782
+
783
+ if wait_tmux and channel :
784
+ from .base import commander # pylint: disable=import-outside-toplevel
785
+
786
+ await commander .async_cmd_raises (
787
+ [commander .get_exec_path ("tmux" ), "wait" , channel ]
788
+ )
769
789
except Exception as error :
770
790
logging .error ("cli server: unexpected exception: %s" , error )
771
791
0 commit comments