Skip to content

Commit 8c8c786

Browse files
authored
feat(shell): Detect TMUX, if exists (#854)
2 parents c4df84c + 6cfa40a commit 8c8c786

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ $ pipx install --suffix=@next 'tmuxp' --pip-args '\--pre' --force
1919

2020
<!-- Maintainers, insert changes / features for the next release here -->
2121

22+
- `tmuxp shell` now detects current `server` via `TMUX` (#854)
23+
2224
## tmuxp 1.21.0 (2022-12-27)
2325

2426
*Maintenance only, no bug fixes or features*

src/tmuxp/cli/shell.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import argparse
22
import os
3+
import pathlib
34
import typing as t
45

56
from libtmux.server import Server
@@ -140,6 +141,17 @@ def command_shell(
140141
- :attr:`libtmux.Server.attached_sessions`, :attr:`libtmux.Session.attached_window`,
141142
:attr:`libtmux.Window.attached_pane`
142143
"""
144+
# If inside a server, detect socket_path
145+
env_tmux = os.getenv("TMUX")
146+
if env_tmux is not None and isinstance(env_tmux, str):
147+
env_socket_path = pathlib.Path(env_tmux.split(",")[0])
148+
if (
149+
env_socket_path.exists()
150+
and args.socket_path is None
151+
and args.socket_name is None
152+
):
153+
args.socket_path = str(env_socket_path)
154+
143155
server = Server(socket_name=args.socket_name, socket_path=args.socket_path)
144156

145157
server.raise_if_dead()

0 commit comments

Comments
 (0)