From 68f7ad2755b67558989400577bcb8d45a0de1d12 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Tue, 27 Dec 2022 11:58:17 -0600 Subject: [PATCH 1/2] feat(shell): Detect TMUX if exists --- src/tmuxp/cli/shell.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/tmuxp/cli/shell.py b/src/tmuxp/cli/shell.py index 9be9b863083..7ea117cbf20 100644 --- a/src/tmuxp/cli/shell.py +++ b/src/tmuxp/cli/shell.py @@ -1,5 +1,6 @@ import argparse import os +import pathlib import typing as t from libtmux.server import Server @@ -140,6 +141,17 @@ def command_shell( - :attr:`libtmux.Server.attached_sessions`, :attr:`libtmux.Session.attached_window`, :attr:`libtmux.Window.attached_pane` """ + # If inside a server, detect socket_path + env_tmux = os.getenv("TMUX") + if env_tmux is not None and isinstance(env_tmux, str): + env_socket_path = pathlib.Path(env_tmux.split(",")[0]) + if ( + env_socket_path.exists() + and args.socket_path is None + and args.socket_name is None + ): + args.socket_path = str(env_socket_path) + server = Server(socket_name=args.socket_name, socket_path=args.socket_path) server.raise_if_dead() From 6cfa40a690477ef4840511ed732715391f2aeb12 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Tue, 27 Dec 2022 12:04:38 -0600 Subject: [PATCH 2/2] docs(CHANGES): Note tmuxp shell improvement --- CHANGES | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES b/CHANGES index 81a590d7fa0..db47a983940 100644 --- a/CHANGES +++ b/CHANGES @@ -19,6 +19,8 @@ $ pipx install --suffix=@next 'tmuxp' --pip-args '\--pre' --force +- `tmuxp shell` now detects current `server` via `TMUX` (#854) + ## tmuxp 1.21.0 (2022-12-27) *Maintenance only, no bug fixes or features*