Skip to content

Commit

Permalink
Progress
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Nov 7, 2020
1 parent 888b2b3 commit 07a6af4
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
53 changes: 50 additions & 3 deletions tmuxp/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,10 @@ def startup(config_dir):
help='Use vi-mode in ptpython/ptipython',
default=False,
)
@click.option('--yes', '-y', 'answer_yes', help='yes', is_flag=True)
@click.option(
'-d', 'detached', help='Load the session without attaching it', is_flag=True
)
def command_shell(
session_name,
window_name,
Expand All @@ -709,6 +713,8 @@ def command_shell(
shell,
use_pythonrc,
use_vi_mode,
detached,
answer_yes,
):
"""Launch python shell for tmux server, session, window and pane.
Expand All @@ -718,15 +724,56 @@ def command_shell(
session)
- ``server.attached_session``, ``session.attached_window``, ``window.attached_pane``
"""
print(f'detached: {detached}')
server = Server(socket_name=socket_name, socket_path=socket_path)

util.raise_if_tmux_not_running(server=server)

current_pane = util.get_current_pane(server=server)

session = util.get_session(
server=server, session_name=session_name, current_pane=current_pane
)
try:
current_session = session = util.get_session(
server=server, current_pane=current_pane
)
except Exception:
current_session = None

try:
session = util.get_session(
server=server, session_name=session_name, current_pane=current_pane
)
except exc.TmuxpException:
if answer_yes or click.confirm(
'Session %s does not exist. Create?' % session_name
if session_name is not None
else 'Session does not exist. Create?'
):
session = server.new_session(session_name=session_name)
else:
return

if current_session is not None and current_session.id != session.id:
print('in')
if not detached and (
answer_yes
or click.confirm(
'Switch / attach to %s and run shell from there?'
% click.style(session_name, fg='green'),
default=True,
)
):
if current_session.id != session.id:
session.attached_window.attached_pane.send_keys(
'tmuxp shell', enter=True
)
if 'TMUX' in os.environ:
session.switch_client()
else:
session.attach_session()
return

if current_pane['session_id'] != session.id:
current_pane = None

window = util.get_window(
session=session, window_name=window_name, current_pane=current_pane
Expand Down
4 changes: 4 additions & 0 deletions tmuxp/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,14 @@ def get_window(session, window_name=None, current_pane=None):
if not window:
raise exc.TmuxpException('Window not found: %s' % window_name)
elif current_pane is not None:
print('get_window: current_pane')
window = session.find_where({'window_id': current_pane['window_id']})
else:
print('get_window: else')
window = session.list_windows()[0]

print(f'get_window: {window}')

return window


Expand Down

0 comments on commit 07a6af4

Please sign in to comment.