Skip to content

Commit fc8d4e2

Browse files
committed
feat(builder): allow environments for windows and panes
This fixes #832.
1 parent 5c222fa commit fc8d4e2

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

src/tmuxp/workspace/builder.py

+2
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ def iter_create_windows(self, session, append=False):
352352
attach=False, # do not move to the new window
353353
window_index=wconf.get("window_index", ""),
354354
window_shell=ws,
355+
environment=panes[0].get("environment", wconf.get("environment")),
355356
)
356357

357358
if is_first_window_pass: # if first window, use window 1
@@ -423,6 +424,7 @@ def get_pane_shell():
423424
start_directory=get_pane_start_directory(),
424425
shell=get_pane_shell(),
425426
target=p.id,
427+
environment=pconf.get("environment", wconf.get("environment")),
426428
)
427429

428430
assert isinstance(p, Pane)
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
session_name: test env vars
22
start_directory: '~'
33
environment:
4-
FOO: BAR
4+
FOO: SESSION
55
PATH: /tmp
6+
options:
7+
default-shell: /bin/sh
68
windows:
7-
- window_name: editor
9+
- window_name: no_overrides
810
panes:
911
- pane
12+
- window_name: window_overrides
13+
environment:
14+
FOO: WINDOW
15+
panes:
16+
- pane
17+
- window_name: pane_overrides
18+
panes:
19+
- environment:
20+
FOO: PANE
21+
- window_name: both_overrides
22+
environment:
23+
FOO: WINDOW
24+
panes:
25+
- pane
26+
- environment:
27+
FOO: PANE

tests/workspace/test_builder.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,32 @@ def test_environment_variables(session):
340340
builder = WorkspaceBuilder(sconf=workspace)
341341
builder.build(session)
342342

343-
assert session.getenv("FOO") == "BAR"
343+
assert session.getenv("FOO") == "SESSION"
344344
assert session.getenv("PATH") == "/tmp"
345345

346+
no_overrides_win = session.windows[0]
347+
pane = no_overrides_win.panes[0]
348+
pane.send_keys("echo $FOO")
349+
assert pane.capture_pane()[1] == "SESSION"
350+
351+
window_overrides_win = session.windows[1]
352+
pane = window_overrides_win.panes[0]
353+
pane.send_keys("echo $FOO")
354+
assert pane.capture_pane()[1] == "WINDOW"
355+
356+
pane_overrides_win = session.windows[2]
357+
pane = pane_overrides_win.panes[0]
358+
pane.send_keys("echo $FOO")
359+
assert pane.capture_pane()[1] == "PANE"
360+
361+
both_overrides_win = session.windows[3]
362+
pane = both_overrides_win.panes[0]
363+
pane.send_keys("echo $FOO")
364+
assert pane.capture_pane()[1] == "WINDOW"
365+
pane = both_overrides_win.panes[1]
366+
pane.send_keys("echo $FOO")
367+
assert pane.capture_pane()[1] == "PANE"
368+
346369

347370
def test_automatic_rename_option(session):
348371
"""With option automatic-rename: on."""

0 commit comments

Comments
 (0)