Skip to content

Commit fc71812

Browse files
committed
Progress
1 parent 77c0cb6 commit fc71812

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

tmuxp/cli.py

+50-3
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,10 @@ def startup(config_dir):
770770
help='Use vi-mode in ptpython/ptipython',
771771
default=False,
772772
)
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+
)
773777
def command_shell(
774778
session_name,
775779
window_name,
@@ -779,6 +783,8 @@ def command_shell(
779783
shell,
780784
use_pythonrc,
781785
use_vi_mode,
786+
detached,
787+
answer_yes,
782788
):
783789
"""Launch python shell for tmux server, session, window and pane.
784790
@@ -788,15 +794,56 @@ def command_shell(
788794
session)
789795
- ``server.attached_session``, ``session.attached_window``, ``window.attached_pane``
790796
"""
797+
print(f'detached: {detached}')
791798
server = Server(socket_name=socket_name, socket_path=socket_path)
792799

793800
util.raise_if_tmux_not_running(server=server)
794801

795802
current_pane = util.get_current_pane(server=server)
796803

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
800847

801848
window = util.get_window(
802849
session=session, window_name=window_name, current_pane=current_pane

tmuxp/util.py

+4
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,14 @@ def get_window(session, window_name=None, current_pane=None):
128128
if not window:
129129
raise exc.TmuxpException('Window not found: %s' % window_name)
130130
elif current_pane is not None:
131+
print('get_window: current_pane')
131132
window = session.find_where({'window_id': current_pane['window_id']})
132133
else:
134+
print('get_window: else')
133135
window = session.list_windows()[0]
134136

137+
print(f'get_window: {window}')
138+
135139
return window
136140

137141

0 commit comments

Comments
 (0)