Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix passing both window command and environment #553

Merged
merged 1 commit into from
Dec 24, 2024

Conversation

ppentchev
Copy link
Contributor

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

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
@CLAassistant
Copy link

CLAassistant commented Dec 24, 2024

CLA assistant check
All committers have signed the CLA.

Copy link

codecov bot commented Dec 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.75%. Comparing base (d1cd071) to head (d93efb9).
Report is 1 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

Copy link
Member

@tony tony left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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 libtmux: test env fix 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
    index 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'
    
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants