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(
350350 window_command : t .Optional [str ] = None ,
351351 x : t .Optional [t .Union [int , "DashLiteral" ]] = None ,
352352 y : t .Optional [t .Union [int , "DashLiteral" ]] = None ,
353+ environment : t .Optional [t .Dict [str , str ]] = None ,
353354 * args : t .Any ,
354355 ** kwargs : t .Any ,
355356 ) -> Session :
@@ -468,6 +469,15 @@ def new_session(
468469 if window_command :
469470 tmux_args += (window_command ,)
470471
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+
471481 proc = self .cmd ("new-session" , * tmux_args )
472482
473483 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:
146146 assert pane .display_message ("#{window_height}" , get_text = True )[0 ] == "32"
147147
148148
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+
149164def test_no_server_sessions () -> None :
150165 """Verify ``Server.sessions`` returns empty list without tmux server."""
151166 server = Server (socket_name = "test_attached_session_no_server" )
You can’t perform that action at this time.
0 commit comments