evnp / tmex

tmux-execute – a lightweight tmux command & layout composer
MIT License
87 stars 5 forks source link

some panes get two commands instead of just one #3

Closed tuxtrooper closed 2 years ago

tuxtrooper commented 2 years ago

I use tmex to log in to multiple servers. Using a 444 layout mostly works, but some panes get two commands instead of one. The problem is caused by "split-window ... -d". The "-d" keeps the focus in the previous pane instead of switching to the newly created pane. Example:

tmex -l 444 'echo 1' 'echo 2' 'echo 3' 'echo 4' 'echo 5' 'echo 6' 'echo 7' 'echo 8' 'echo 9' 'echo 10' 'echo 11' 'echo 12'

The 3rd row remains emtpy, the 1st row gets two echo commands. If "-d" is removed in line 365, the command above works as I expect it to:

diff ./tmex tmex.SAV20220704 
365,366c365
<     #tmuxargs+=( ";" "split-window" "-${direction}" "-p${percentage}" "-d" )
<     tmuxargs+=( ";" "split-window" "-${direction}" "-p${percentage}" )
---
>     tmuxargs+=( ";" "split-window" "-${direction}" "-p${percentage}" "-d" )

A big thanks for tmex! Great scripting skills! :-)

saravanaskanda commented 2 years ago

Q____

evnp commented 2 years ago

Hey @tuxtrooper, thanks for the bug report and the straightforward repro instructions! Sorry about the delay, been a busy month. There is indeed a bug in the command execution logic related to -d, I'm not sure if tmux's split-window behavior changed somewhere along the way, or if it's always been present.

I've added a fix which avoids using -d as you suggest, and adds one bit of pane-selection logic to accomplish what -d was doing previously: https://github.com/evnp/tmex/commit/845981cd6f7a91ef5842d284b50d248b038d9de6

I've verified this fix works on my local setup, and retains behavior for all other layout/command cases I've thrown at it. If you could pull the latest version of the script from https://github.com/evnp/tmex/blob/845981cd6f7a91ef5842d284b50d248b038d9de6/tmex and see if it fixes the issue for you pre-release, that'd be great – or I can cut a release for it if you prefer that.

Glad you've found the project useful, despite some quirks!

tuxtrooper commented 2 years ago

Hi Evan,

the new version of the script works for the example and also for bigger layouts. Thanks for fixing the bug and improving the pane-selection. :-)

Best Regards, Hans

evnp commented 2 years ago

Thanks again for the help with this Hans! I've published https://github.com/evnp/tmex/releases/tag/v1.0.9 with the fix.