Skip to content

Commit 20b42f2

Browse files
committed
fixup! feat(Window.split_window): set up environment
1 parent b4d9f23 commit 20b42f2

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/libtmux/window.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import shlex
1010
import typing as t
1111

12-
from libtmux.common import tmux_cmd
12+
from libtmux.common import has_gte_version, tmux_cmd
1313
from libtmux.pane import Pane
1414

1515
from . import exc, formats
@@ -522,8 +522,13 @@ def split_window(
522522
tmux_args += ("-d",)
523523

524524
if environment:
525-
for k, v in environment.items():
526-
tmux_args += ("-e%s=%s" % (k, v),)
525+
if has_gte_version("3.0"):
526+
for k, v in environment.items():
527+
tmux_args += ("-e%s=%s" % (k, v),)
528+
else:
529+
logger.warning(
530+
"Cannot set up environment as tmux 3.0 or newer is required."
531+
)
527532

528533
if shell:
529534
tmux_args += (shell,)

tests/test_window.py

+26
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ def test_empty_window_name(session: Session) -> None:
314314
assert "''" in cmd.stdout
315315

316316

317+
@pytest.mark.skipif(
318+
has_lt_version("3.0"),
319+
reason="needs -e flag for split-window which was introduced in 3.0",
320+
)
317321
def test_split_window_with_environment(session: Session) -> None:
318322
env = shutil.which("env")
319323
assert env is not None, "Cannot find usable `env` in Path."
@@ -328,3 +332,25 @@ def test_split_window_with_environment(session: Session) -> None:
328332
time.sleep(0.05)
329333
pane.send_keys("echo $ENV_VAR")
330334
assert pane.capture_pane() == ["$ echo $ENV_VAR", "pane", "$"]
335+
336+
337+
@pytest.mark.skipif(
338+
has_gte_version("3.0"),
339+
reason="3.0 has the -e flag on split-window",
340+
)
341+
def test_split_window_with_environment_logs_warning_for_old_tmux(
342+
session: Session,
343+
caplog: pytest.LogCaptureFixture,
344+
) -> None:
345+
env = shutil.which("env")
346+
assert env is not None, "Cannot find usable `env` in Path."
347+
348+
window = session.new_window(window_name="split_window_with_environment")
349+
window.split_window(
350+
shell=f"{env} PS1='$ ' bash --norc --noprofile",
351+
environment={"ENV_VAR": "pane"},
352+
)
353+
354+
assert any(
355+
"Cannot set up environment" in record.msg for record in caplog.records
356+
), "Warning missing"

0 commit comments

Comments
 (0)