Skip to content

feat(shell): Detect TMUX, if exists #854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ $ pipx install --suffix=@next 'tmuxp' --pip-args '\--pre' --force

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

- `tmuxp shell` now detects current `server` via `TMUX` (#854)

## tmuxp 1.21.0 (2022-12-27)

*Maintenance only, no bug fixes or features*
Expand Down
12 changes: 12 additions & 0 deletions src/tmuxp/cli/shell.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import os
import pathlib
import typing as t

from libtmux.server import Server
Expand Down Expand Up @@ -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()
Expand Down