@@ -848,6 +848,10 @@ def startup(config_dir):
848848 help = "Use vi-mode in ptpython/ptipython" ,
849849 default = False ,
850850)
851+ @click .option ("--yes" , "-y" , "answer_yes" , help = "yes" , is_flag = True )
852+ @click .option (
853+ "-d" , "detached" , help = "Load the session without attaching it" , is_flag = True
854+ )
851855def command_shell (
852856 session_name ,
853857 window_name ,
@@ -857,6 +861,8 @@ def command_shell(
857861 shell ,
858862 use_pythonrc ,
859863 use_vi_mode ,
864+ detached ,
865+ answer_yes ,
860866):
861867 """Launch python shell for tmux server, session, window and pane.
862868
@@ -866,15 +872,38 @@ def command_shell(
866872 session)
867873 - ``server.attached_session``, ``session.attached_window``, ``window.attached_pane``
868874 """
875+ print (f"detached: { detached } " )
869876 server = Server (socket_name = socket_name , socket_path = socket_path )
870877
871- util .raise_if_tmux_not_running (server = server )
878+ if not util .is_server_running (server = server ):
879+ if answer_yes or click .confirm (
880+ "No tmux server running, create?" ,
881+ default = True ,
882+ ):
883+ session = server .new_session (
884+ session_name = session_name or "tmuxp shell" ,
885+ window_command = " " .join (sys .argv ),
886+ )
887+ session .attach_session ()
888+ else :
889+ current_pane = util .get_current_pane (server = server )
872890
873- current_pane = util .get_current_pane (server = server )
891+ try :
892+ session = util .get_session (
893+ server = server , session_name = session_name , current_pane = current_pane
894+ )
895+ except exc .TmuxpException :
896+ if answer_yes or click .confirm (
897+ "Session %s does not exist. Create?" % session_name
898+ if session_name is not None
899+ else "Session does not exist. Create?"
900+ ):
901+ session = server .new_session (session_name = session_name )
902+ else :
903+ return
874904
875- session = util .get_session (
876- server = server , session_name = session_name , current_pane = current_pane
877- )
905+ if current_pane ["session_id" ] != session .id :
906+ current_pane = None
878907
879908 window = util .get_window (
880909 session = session , window_name = window_name , current_pane = current_pane
0 commit comments