Skip to content
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

Fix passing both window command and environment #553

Merged
merged 1 commit into from
Dec 24, 2024
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
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
Loading