Skip to content

Commit 07a6af4

Browse files
committed
Progress
1 parent 888b2b3 commit 07a6af4

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

Diff for: tmuxp/cli.py

+50-3
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,10 @@ def startup(config_dir):
700700
help='Use vi-mode in ptpython/ptipython',
701701
default=False,
702702
)
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+
)
703707
def command_shell(
704708
session_name,
705709
window_name,
@@ -709,6 +713,8 @@ def command_shell(
709713
shell,
710714
use_pythonrc,
711715
use_vi_mode,
716+
detached,
717+
answer_yes,
712718
):
713719
"""Launch python shell for tmux server, session, window and pane.
714720
@@ -718,15 +724,56 @@ def command_shell(
718724
session)
719725
- ``server.attached_session``, ``session.attached_window``, ``window.attached_pane``
720726
"""
727+
print(f'detached: {detached}')
721728
server = Server(socket_name=socket_name, socket_path=socket_path)
722729

723730
util.raise_if_tmux_not_running(server=server)
724731

725732
current_pane = util.get_current_pane(server=server)
726733

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
730777

731778
window = util.get_window(
732779
session=session, window_name=window_name, current_pane=current_pane

Diff for: tmuxp/util.py

+4
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,14 @@ def get_window(session, window_name=None, current_pane=None):
125125
if not window:
126126
raise exc.TmuxpException('Window not found: %s' % window_name)
127127
elif current_pane is not None:
128+
print('get_window: current_pane')
128129
window = session.find_where({'window_id': current_pane['window_id']})
129130
else:
131+
print('get_window: else')
130132
window = session.list_windows()[0]
131133

134+
print(f'get_window: {window}')
135+
132136
return window
133137

134138

0 commit comments

Comments
 (0)