File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -350,6 +350,7 @@ def new_session(
350
350
window_command : t .Optional [str ] = None ,
351
351
x : t .Optional [t .Union [int , "DashLiteral" ]] = None ,
352
352
y : t .Optional [t .Union [int , "DashLiteral" ]] = None ,
353
+ environment : t .Optional [t .Dict [str , str ]] = None ,
353
354
* args : t .Any ,
354
355
** kwargs : t .Any ,
355
356
) -> Session :
@@ -468,6 +469,15 @@ def new_session(
468
469
if window_command :
469
470
tmux_args += (window_command ,)
470
471
472
+ if environment :
473
+ if has_gte_version ("3.2" ):
474
+ for k , v in environment .items ():
475
+ tmux_args += (f"-e{ k } ={ v } " ,)
476
+ else :
477
+ logger .warning (
478
+ "Environment flag ignored, tmux 3.2 or newer required." ,
479
+ )
480
+
471
481
proc = self .cmd ("new-session" , * tmux_args )
472
482
473
483
if proc .stderr :
Original file line number Diff line number Diff line change @@ -146,6 +146,21 @@ def test_new_session_width_height(server: Server) -> None:
146
146
assert pane .display_message ("#{window_height}" , get_text = True )[0 ] == "32"
147
147
148
148
149
+ def test_new_session_environmental_variables (
150
+ server : Server ,
151
+ caplog : pytest .LogCaptureFixture ,
152
+ ) -> None :
153
+ """Server.new_session creates and returns valid session."""
154
+ my_session = server .new_session ("test_new_session" , environment = {"FOO" : "HI" })
155
+
156
+ if has_gte_version ("3.2" ):
157
+ assert my_session .show_environment ()["FOO" ] == "HI"
158
+ else :
159
+ assert any (
160
+ "Environment flag ignored" in record .msg for record in caplog .records
161
+ ), "Warning missing"
162
+
163
+
149
164
def test_no_server_sessions () -> None :
150
165
"""Verify ``Server.sessions`` returns empty list without tmux server."""
151
166
server = Server (socket_name = "test_attached_session_no_server" )
You can’t perform that action at this time.
0 commit comments