@@ -848,6 +848,10 @@ def startup(config_dir):
848
848
help = "Use vi-mode in ptpython/ptipython" ,
849
849
default = False ,
850
850
)
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
+ )
851
855
def command_shell (
852
856
session_name ,
853
857
window_name ,
@@ -857,6 +861,8 @@ def command_shell(
857
861
shell ,
858
862
use_pythonrc ,
859
863
use_vi_mode ,
864
+ detached ,
865
+ answer_yes ,
860
866
):
861
867
"""Launch python shell for tmux server, session, window and pane.
862
868
@@ -866,15 +872,38 @@ def command_shell(
866
872
session)
867
873
- ``server.attached_session``, ``session.attached_window``, ``window.attached_pane``
868
874
"""
875
+ print (f"detached: { detached } " )
869
876
server = Server (socket_name = socket_name , socket_path = socket_path )
870
877
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 )
872
890
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
874
904
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
878
907
879
908
window = util .get_window (
880
909
session = session , window_name = window_name , current_pane = current_pane
0 commit comments