Skip to content

Commit

Permalink
fix(server[new_session]): Fix passing both window command and environ…
Browse files Browse the repository at this point in the history
…ment (#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.
  • Loading branch information
ppentchev authored Dec 24, 2024
1 parent d1cd071 commit 9b955da
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/libtmux/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,6 @@ def new_session(
if y is not None:
tmux_args += ("-y", y)

if window_command:
tmux_args += (window_command,)

if environment:
if has_gte_version("3.2"):
for k, v in environment.items():
Expand All @@ -511,6 +508,9 @@ def new_session(
"Environment flag ignored, tmux 3.2 or newer required.",
)

if window_command:
tmux_args += (window_command,)

proc = self.cmd("new-session", *tmux_args)

if proc.stderr:
Expand Down
24 changes: 24 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Test for libtmux Server object."""

import logging
import os
import subprocess
import time

import pytest

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


def test_new_session_shell_env(server: Server) -> None:
"""Verify ``Server.new_session`` creates valid session running w/ command."""
cmd = "sleep 1m"
env = dict(os.environ)
mysession = server.new_session(
"test_new_session_env", window_command=cmd, environment=env
)
time.sleep(0.1)
window = mysession.windows[0]
pane = window.panes[0]
assert mysession.session_name == "test_new_session_env"
assert server.has_session("test_new_session_env")

pane_start_command = pane.pane_start_command
assert pane_start_command is not None

if has_gte_version("3.2"):
assert pane_start_command.replace('"', "") == cmd
else:
assert pane_start_command == cmd


@pytest.mark.skipif(has_version("3.2"), reason="Wrong width returned with 3.2")
def test_new_session_width_height(server: Server) -> None:
"""Verify ``Server.new_session`` creates valid session running w/ dimensions."""
Expand Down

0 comments on commit 9b955da

Please sign in to comment.