Skip to content

Commit f279d1a

Browse files
committed
Server(feat[new_session]): add detach-others, no-size, config flags
why: new-session supports flags for detaching other clients, suppressing initial sizing, and specifying config files that were not exposed. what: - Add detach_others (-D), no_size (-X), config_file (-f) parameters - Skip -A (attach-or-create) as it requires a terminal and does not work in libtmux's programmatic non-terminal context - Add test for config_file parameter
1 parent a402132 commit f279d1a

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

src/libtmux/server.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,9 @@ def new_session(
472472
y: int | DashLiteral | None = None,
473473
environment: dict[str, str] | None = None,
474474
*args: t.Any,
475+
detach_others: bool | None = None,
476+
no_size: bool | None = None,
477+
config_file: StrPath | None = None,
475478
**kwargs: t.Any,
476479
) -> Session:
477480
"""Create new session, returns new :class:`Session`.
@@ -518,6 +521,18 @@ def new_session(
518521
y : int | str, optional
519522
Force the specified height instead of the tmux default for a
520523
detached session
524+
detach_others : bool, optional
525+
Detach other clients from the session (``-D`` flag).
526+
527+
.. versionadded:: 0.45
528+
no_size : bool, optional
529+
Do not set the initial window size (``-X`` flag).
530+
531+
.. versionadded:: 0.45
532+
config_file : str or PathLike, optional
533+
Specify an alternative configuration file (``-f`` flag).
534+
535+
.. versionadded:: 0.45
521536
522537
Returns
523538
-------
@@ -585,6 +600,15 @@ def new_session(
585600
f"-F{format_string}",
586601
)
587602

603+
if detach_others:
604+
tmux_args += ("-D",)
605+
606+
if no_size:
607+
tmux_args += ("-X",)
608+
609+
if config_file is not None:
610+
tmux_args += ("-f", str(pathlib.Path(config_file).expanduser()))
611+
588612
if session_name is not None:
589613
tmux_args += (f"-s{session_name}",)
590614

tests/test_server.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,3 +458,18 @@ def test_tmux_bin_invalid_path_raise_if_dead() -> None:
458458
s = Server(tmux_bin="/nonexistent/tmux")
459459
with pytest.raises(exc.TmuxCommandNotFound):
460460
s.raise_if_dead()
461+
462+
463+
def test_new_session_config_file(
464+
server: Server,
465+
tmp_path: pathlib.Path,
466+
) -> None:
467+
"""Test Server.new_session() with config_file flag."""
468+
conf = tmp_path / "test.conf"
469+
conf.write_text("set -g status off\n")
470+
471+
session = server.new_session(
472+
session_name="conf_test",
473+
config_file=str(conf),
474+
)
475+
assert session.session_name == "conf_test"

0 commit comments

Comments
 (0)