Skip to content

Commit 9b955da

Browse files
authored
fix(server[new_session]): Fix passing both window command and environment (#553)
If the `-e this=that` options are passed after a window command, tmux (correctly, IMHO) interprets them as options to be passed to the command itself, does not change the environment, and passes them through to the command, which does not usually expect to get a whole lot of `-e this=that -e other=something` options.
1 parent d1cd071 commit 9b955da

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/libtmux/server.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,6 @@ def new_session(
499499
if y is not None:
500500
tmux_args += ("-y", y)
501501

502-
if window_command:
503-
tmux_args += (window_command,)
504-
505502
if environment:
506503
if has_gte_version("3.2"):
507504
for k, v in environment.items():
@@ -511,6 +508,9 @@ def new_session(
511508
"Environment flag ignored, tmux 3.2 or newer required.",
512509
)
513510

511+
if window_command:
512+
tmux_args += (window_command,)
513+
514514
proc = self.cmd("new-session", *tmux_args)
515515

516516
if proc.stderr:

tests/test_server.py

+24
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"""Test for libtmux Server object."""
22

33
import logging
4+
import os
45
import subprocess
6+
import time
57

68
import pytest
79

@@ -131,6 +133,28 @@ def test_new_session_shell(server: Server) -> None:
131133
assert pane_start_command == cmd
132134

133135

136+
def test_new_session_shell_env(server: Server) -> None:
137+
"""Verify ``Server.new_session`` creates valid session running w/ command."""
138+
cmd = "sleep 1m"
139+
env = dict(os.environ)
140+
mysession = server.new_session(
141+
"test_new_session_env", window_command=cmd, environment=env
142+
)
143+
time.sleep(0.1)
144+
window = mysession.windows[0]
145+
pane = window.panes[0]
146+
assert mysession.session_name == "test_new_session_env"
147+
assert server.has_session("test_new_session_env")
148+
149+
pane_start_command = pane.pane_start_command
150+
assert pane_start_command is not None
151+
152+
if has_gte_version("3.2"):
153+
assert pane_start_command.replace('"', "") == cmd
154+
else:
155+
assert pane_start_command == cmd
156+
157+
134158
@pytest.mark.skipif(has_version("3.2"), reason="Wrong width returned with 3.2")
135159
def test_new_session_width_height(server: Server) -> None:
136160
"""Verify ``Server.new_session`` creates valid session running w/ dimensions."""

0 commit comments

Comments
 (0)