@@ -770,6 +770,10 @@ def startup(config_dir):
770
770
help = 'Use vi-mode in ptpython/ptipython' ,
771
771
default = False ,
772
772
)
773
+ @click .option ('--yes' , '-y' , 'answer_yes' , help = 'yes' , is_flag = True )
774
+ @click .option (
775
+ '-d' , 'detached' , help = 'Load the session without attaching it' , is_flag = True
776
+ )
773
777
def command_shell (
774
778
session_name ,
775
779
window_name ,
@@ -779,6 +783,8 @@ def command_shell(
779
783
shell ,
780
784
use_pythonrc ,
781
785
use_vi_mode ,
786
+ detached ,
787
+ answer_yes ,
782
788
):
783
789
"""Launch python shell for tmux server, session, window and pane.
784
790
@@ -788,15 +794,56 @@ def command_shell(
788
794
session)
789
795
- ``server.attached_session``, ``session.attached_window``, ``window.attached_pane``
790
796
"""
797
+ print (f'detached: { detached } ' )
791
798
server = Server (socket_name = socket_name , socket_path = socket_path )
792
799
793
800
util .raise_if_tmux_not_running (server = server )
794
801
795
802
current_pane = util .get_current_pane (server = server )
796
803
797
- session = util .get_session (
798
- server = server , session_name = session_name , current_pane = current_pane
799
- )
804
+ try :
805
+ current_session = session = util .get_session (
806
+ server = server , current_pane = current_pane
807
+ )
808
+ except Exception :
809
+ current_session = None
810
+
811
+ try :
812
+ session = util .get_session (
813
+ server = server , session_name = session_name , current_pane = current_pane
814
+ )
815
+ except exc .TmuxpException :
816
+ if answer_yes or click .confirm (
817
+ 'Session %s does not exist. Create?' % session_name
818
+ if session_name is not None
819
+ else 'Session does not exist. Create?'
820
+ ):
821
+ session = server .new_session (session_name = session_name )
822
+ else :
823
+ return
824
+
825
+ if current_session is not None and current_session .id != session .id :
826
+ print ('in' )
827
+ if not detached and (
828
+ answer_yes
829
+ or click .confirm (
830
+ 'Switch / attach to %s and run shell from there?'
831
+ % click .style (session_name , fg = 'green' ),
832
+ default = True ,
833
+ )
834
+ ):
835
+ if current_session .id != session .id :
836
+ session .attached_window .attached_pane .send_keys (
837
+ 'tmuxp shell' , enter = True
838
+ )
839
+ if 'TMUX' in os .environ :
840
+ session .switch_client ()
841
+ else :
842
+ session .attach_session ()
843
+ return
844
+
845
+ if current_pane ['session_id' ] != session .id :
846
+ current_pane = None
800
847
801
848
window = util .get_window (
802
849
session = session , window_name = window_name , current_pane = current_pane
0 commit comments