Skip to content

Commit 3576909

Browse files
committed
feat(Window.split_window): set up environment
This allows to set up a custom environment when creating a new pane.
1 parent b4c98a0 commit 3576909

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/libtmux/window.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ def split_window(
442442
vertical: bool = True,
443443
shell: t.Optional[str] = None,
444444
percent: t.Optional[int] = None,
445+
environment: t.Optional[t.Dict[str, str]] = None,
445446
) -> Pane:
446447
"""
447448
Split window and return the created :class:`Pane`.
@@ -520,6 +521,10 @@ def split_window(
520521
if not attach:
521522
tmux_args += ("-d",)
522523

524+
if environment:
525+
for k, v in environment.items():
526+
tmux_args += ("-e%s=%s" % (k, v),)
527+
523528
if shell:
524529
tmux_args += (shell,)
525530

tests/test_window.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Test for libtmux Window object."""
22
import logging
3+
import time
34
import typing as t
45

56
import pytest
@@ -310,3 +311,16 @@ def test_empty_window_name(session: Session) -> None:
310311
"#{==:#{session_name}," + session.name + "}",
311312
)
312313
assert "''" in cmd.stdout
314+
315+
316+
def test_split_window_with_environment(session: Session) -> None:
317+
window = session.new_window(window_name="split_window_with_environment")
318+
pane = window.split_window(
319+
shell="/usr/bin/env PS1='$ ' bash --norc --noprofile",
320+
environment={"ENV_VAR": "pane"},
321+
)
322+
assert pane is not None
323+
# wait a bit for the prompt to be ready as the test gets flaky otherwise
324+
time.sleep(0.05)
325+
pane.send_keys("echo $ENV_VAR")
326+
assert pane.capture_pane() == ["$ echo $ENV_VAR", "pane", "$"]

0 commit comments

Comments
 (0)