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

Issue with using -t in pane commands in session files #915

Closed
GBlackburnMicrosoft opened this issue Mar 6, 2024 · 10 comments
Closed

Issue with using -t in pane commands in session files #915

GBlackburnMicrosoft opened this issue Mar 6, 2024 · 10 comments

Comments

@GBlackburnMicrosoft
Copy link

GBlackburnMicrosoft commented Mar 6, 2024

This issue is observed with both tmuxp 1.40.0 and 1.39.0, it was not present in 1.9.4.

Summary

When a pane command includes the string -t it will not enter that command into the pane and will instead print it to screen in the shell where you ran the tmuxp command.

Reproduction

Example configuration file:

session_name: "Some-Session"
windows:
  - window_name: "Some-Window"
    layout: tiled
    panes:
      - shell_command:
        - echo "t - This echo's correctly."
      - shell_command:
        - echo "-a - This also echo's correctly."
      - shell_command:
        - echo "-t - This is never sent to the pane and instead printed to the current shell."

Expected:
Load this template using tmuxp load and you'll get three panes, all three panes have echoed out the expected message.

Current outcome:
When loading this template only the first two panes will have echoed out the expected message and the final one with -t in it then it prints out to the current shell.

@tony
Copy link
Member

tony commented Mar 6, 2024 via email

@tony
Copy link
Member

tony commented Mar 9, 2024

@GBlackburnMicrosoft #916 has a recreation attempt using that tmux config almost exactly (across an array of tmux + python versions)

By deduction: This is potentially connected to your shell, shell configuration, or tmux configuration.

Can you provide these:

  • A screenshot (to confirm what the final results looks like)
  • tmuxp debug-info
    • tmux -V
    • tmuxp -V

On your side:

  • can you try tmuxp load -L test -f /dev/null <path-to-config>? That will emulate a blank config, it's equivalent to tmux -L test (socket name of test to not interrupt existing tmux sessions.
  • can you try experimenting with different shells / with and without shell configs? If you deduce what it was, it may be useful for others to know, and libtmux/tmuxp could use it to improve compatibility.

@GBlackburnMicrosoft
Copy link
Author

Darn, I had hoped it wasn't a shell issue. Narrowing those down is painful. Here's the screenshot of after I've loaded my reproduction config above and appended it to the current session (note this is in my window after running tmux -Ltest new then using tmuxp load -L test -f /dev/null <path-to-config>:

image

Version details:

gblackburn:~/code/temp $ tmux -V
tmux 3.2a
gblackburn:~/code/temp $ tmuxp -V
tmuxp 1.40.0, libtmux 0.32.0

Debug info:
debug-info.log

I'll have a play around with my shell and see if removing something solves the issue. Thanks for taking a look and attempting to repro.

@GBlackburnMicrosoft
Copy link
Author

I have just done another test with 1.9.4 and didn't see the issue. Sounds like there's some binary chopping I can do as well to narrow down when this was introduced.

@GBlackburnMicrosoft
Copy link
Author

GBlackburnMicrosoft commented Mar 14, 2024

I've done the binary chopping and it all works as expected when:

gblackburn:~ $ tmuxp --version
tmuxp 1.36.0, libtmux 0.27.1

but I start seeing the issue when:

gblackburn:~ $ tmuxp --version
tmuxp 1.37.0, libtmux 0.28.1

From looking at the changelog the only change here is to take 0.28.0 of libtmux so potentially the issue is with them.

I'm going to do a little digging into my environment.

@GBlackburnMicrosoft
Copy link
Author

I've done some more testing locally and I only see the issue when running the tmuxp command from within another tmux session and appending the template. If I run it from outside a tmux session then it works just fine.

I've managed to reproduce this in a UT (basically building on your one) in https://github.com/tmux-python/tmuxp/pull/917/files. Although I haven't had it run in Gitlab I could confirm locally that it reproduces the issue.

I'm unsure whether this is an issue with libtmux or how tmuxp is using it. I suspect that the relevant change in libtmux is:

@@ -113,7 +120,7 @@ class Pane(Obj):
         Specifying ``('-t', 'custom-target')`` or ``('-tcustom_target')`` in
         ``args`` will override using the object's ``pane_id`` as target.
         """
-        if not any(arg.startswith("-t") for arg in args):
+        if not any("-t" in str(x) for x in args):
             args = ("-t", self.pane_id, *args)
 
         return self.server.cmd(cmd, *args, **kwargs)

@tony
Copy link
Member

tony commented Mar 16, 2024

I've done some more testing locally and I only see the issue when running the tmuxp command from within another tmux session and appending the template. If I run it from outside a tmux session then it works just fine.

Good obversation.

@GBlackburnMicrosoft Do you want credit for it for the fix on libtmux? If you want to make a PR against libtmux you can, so it shows up in git history. If not, I can make the change.

@tony
Copy link
Member

tony commented Mar 17, 2024

If you want to make a PR against libtmux you can

@GBlackburnMicrosoft For this purpose, I will make the change. Based on finding tmux-python/libtmux#533 + CiscoDevNet/virlutils#148, this needs a different approach to ensure compatibility.

I think cmd needs:

  • to have a target to passed as an optional keyword argument
  • the if condition idiom needs to be removed entirely
  • raise a warning if trying to pass a real target (any variation where [..., '-t', '{target value}'] or ['-t{target_value}'])

tony added a commit to tmux-python/libtmux that referenced this issue Mar 17, 2024
tony added a commit that referenced this issue Mar 17, 2024
This should alleviate issues with `-t` values of pane / shell commands.

See also:
- tmux-python/libtmux#535
- #915
tony added a commit to GBlackburnMicrosoft/tmuxp that referenced this issue Mar 17, 2024
@tony
Copy link
Member

tony commented Mar 17, 2024

@GBlackburnMicrosoft If you try tmuxp v1.42.0 (PyPI, changes, release), via libtmux v0.34.0 (PyPI, changes, release), is anything different?

@GBlackburnMicrosoft
Copy link
Author

That all seems to be working now! I'm able to append panes with -t in the command. Thanks so much for sorting this out 😊

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

No branches or pull requests

2 participants