@@ -700,6 +700,10 @@ def startup(config_dir):
700
700
help = 'Use vi-mode in ptpython/ptipython' ,
701
701
default = False ,
702
702
)
703
+ @click .option ('--yes' , '-y' , 'answer_yes' , help = 'yes' , is_flag = True )
704
+ @click .option (
705
+ '-d' , 'detached' , help = 'Load the session without attaching it' , is_flag = True
706
+ )
703
707
def command_shell (
704
708
session_name ,
705
709
window_name ,
@@ -709,6 +713,8 @@ def command_shell(
709
713
shell ,
710
714
use_pythonrc ,
711
715
use_vi_mode ,
716
+ detached ,
717
+ answer_yes ,
712
718
):
713
719
"""Launch python shell for tmux server, session, window and pane.
714
720
@@ -718,15 +724,56 @@ def command_shell(
718
724
session)
719
725
- ``server.attached_session``, ``session.attached_window``, ``window.attached_pane``
720
726
"""
727
+ print (f'detached: { detached } ' )
721
728
server = Server (socket_name = socket_name , socket_path = socket_path )
722
729
723
730
util .raise_if_tmux_not_running (server = server )
724
731
725
732
current_pane = util .get_current_pane (server = server )
726
733
727
- session = util .get_session (
728
- server = server , session_name = session_name , current_pane = current_pane
729
- )
734
+ try :
735
+ current_session = session = util .get_session (
736
+ server = server , current_pane = current_pane
737
+ )
738
+ except Exception :
739
+ current_session = None
740
+
741
+ try :
742
+ session = util .get_session (
743
+ server = server , session_name = session_name , current_pane = current_pane
744
+ )
745
+ except exc .TmuxpException :
746
+ if answer_yes or click .confirm (
747
+ 'Session %s does not exist. Create?' % session_name
748
+ if session_name is not None
749
+ else 'Session does not exist. Create?'
750
+ ):
751
+ session = server .new_session (session_name = session_name )
752
+ else :
753
+ return
754
+
755
+ if current_session is not None and current_session .id != session .id :
756
+ print ('in' )
757
+ if not detached and (
758
+ answer_yes
759
+ or click .confirm (
760
+ 'Switch / attach to %s and run shell from there?'
761
+ % click .style (session_name , fg = 'green' ),
762
+ default = True ,
763
+ )
764
+ ):
765
+ if current_session .id != session .id :
766
+ session .attached_window .attached_pane .send_keys (
767
+ 'tmuxp shell' , enter = True
768
+ )
769
+ if 'TMUX' in os .environ :
770
+ session .switch_client ()
771
+ else :
772
+ session .attach_session ()
773
+ return
774
+
775
+ if current_pane ['session_id' ] != session .id :
776
+ current_pane = None
730
777
731
778
window = util .get_window (
732
779
session = session , window_name = window_name , current_pane = current_pane
0 commit comments