Fix passing both window command and environment#553
Merged
tony merged 1 commit intotmux-python:masterfrom Dec 24, 2024
Merged
Conversation
If the `-e this=that` options are passed after a window command, tmux (correctly, IMHO) interprets them as options to be passed to the command itself, does not change the environment, and passes them through to the command, which does not usually expect to get a whole lot of `-e this=that -e other=something` options. For a demonstration, see https://gitlab.com/-/snippets/4782141
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #553 +/- ##
==========================================
+ Coverage 88.70% 88.75% +0.04%
==========================================
Files 36 36
Lines 3914 3930 +16
Branches 359 360 +1
==========================================
+ Hits 3472 3488 +16
Misses 307 307
Partials 135 135 ☔ View full report in Codecov by Sentry. |
tony
approved these changes
Dec 24, 2024
Member
There was a problem hiding this comment.
@ppentchev Thank you, this works perfect!
I will cut a release of this on libtmux and tmuxp.
-
✅ CI passes
-
✅ Did a test on tmuxp at tmux-python/tmuxp#955
uv add 'git+https://github.com/ppentchev/libtmux' --branch=pp-command-env -
✅ Test confirmation
Assume this:
diff --git a/src/libtmux/server.py b/src/libtmux/server.py ind 8000 ex 89ea2b9..04e07b7 100644 --- a/src/libtmux/server.py +++ b/src/libtmux/server.py @@ -499,6 +499,9 @@ class Server(EnvironmentMixin): if y is not None: tmux_args += ("-y", y) + if window_command: + tmux_args += (window_command,) + if environment: if has_gte_version("3.2"): for k, v in environment.items(): @@ -508,9 +511,6 @@ class Server(EnvironmentMixin): "Environment flag ignored, tmux 3.2 or newer required.", ) - if window_command: - tmux_args += (window_command,) - proc = self.cmd("new-session", *tmux_args) if proc.stderr:
py.test:_________________ test_new_session_shell_env __________________ tests/test_server.py:144: in test_new_session_shell_env window = mysession.windows[0] cmd = 'sleep 1m' env = {...} mysession = Session($0 test_new_session_env) server = Server(socket_name=libtmux_testylp6b5ge) src/libtmux/session.py:111: in windows for obj in fetch_objs( self = Session($0 test_new_session_env) src/libtmux/neo.py:219: in fetch_objs raise exc.LibTmuxException(proc.stderr) E libtmux.exc.LibTmuxException: ['no server running on /tmp/tmux-1000/libtmux_testylp6b5ge'] cmd_args = ['-Llibtmux_testylp6b5ge'] formats = ['server', 'active_window_index', 'alternate_saved_x', 'alternate_saved_y', 'buffer_name', 'buffer_sample', ...] list_cmd = 'list-windows' list_extra_args = ['-t', '$0'] proc = <libtmux.common.tmux_cmd object at 0x7faa0d280bb0> server = Server(socket_name=libtmux_testylp6b5ge) tmux_cmds = ['-Llibtmux_testylp6b5ge', 'list-windows', '-t', '$0', '-F#{server}␞#{active_window_index}␞#{alternate_saved_x}␞#{alte..._offset_x}␞#{window_offset_y}␞#{window_panes}␞#{window_raw_flags}␞#{window_stack_index}␞#{window_width}␞#{wrap_flag}␞'] tmux_formats = ['#{server}␞', '#{active_window_index}␞', '#{alternate_saved_x}␞', '#{alternate_saved_y}␞', '#{buffer_name}␞', '#{buffer_sample}␞', ...] =================== short test summary info =================== FAILED tests/test_server.py::test_new_session_shell_env - libtmux.exc.LibTmuxException: ['no server running on /tmp/... ===== 1 failed, 445 passed, 7 skipped, 2 rerun in 26.18s ====== make[1]: *** [Makefile:15: test] Error 1 make[1]: Leaving directory '/home/t/work/python/libtmux'
tony
added a commit
that referenced
this pull request
Dec 24, 2024
tony
added a commit
to tmux-python/tmuxp
that referenced
this pull request
Dec 24, 2024
tony
added a commit
to tmux-python/tmuxp
that referenced
this pull request
Dec 24, 2024
tony
added a commit
to tmux-python/tmuxp
that referenced
this pull request
Dec 24, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If the
-e this=thatoptions are passed after a window command, tmux (correctly, IMHO) interprets them as options to be passed to the command itself, does not change the environment, and passes them through to the command, which does not usually expect to get a whole lot of-e this=that -e other=somethingoptions.For a demonstration, see https://gitlab.com/-/snippets/4782141