7

I routinely join panes in tmux, and would like to create a binding that would prompt me for the window to join, while still letting me see the window numbers and titles. My first approach was based one of the answers to this question:

bind-key < command-prompt -p "create pane from #(tmux list-windows|awk -vORS='  ' '/^[0-9]/{print $1 $2}'):"  "join-pane -s ':%%'"

But tmux does not do the interpolation it does with other commands such as "display-message", and the prompt itself is taking up the status line so I cannot see the window numbers and titles.

My second approach was to attempt to leverage choose-window, which displays an interactive list of windows:

bind < choose-window "join-pane -hs %%"

This mostly works, but it takes up the entire current window while I'm choosing. I would like to do something like bufexplore does in vim where the window is split first, then a prompt appears in the new pane where I select the window to pull into it. The following seems pretty close to what I want, but I'm left with the pane that was used to display the prompt sitting around:

bind < split-window -h \; choose-window 'join-pane -hs %%'

I'd move the window instead, but, as far as I can tell, you can't move a window to a pane (or move a pane at all without joining), and the following does not work:

bind < split-window -h ; choose-window 'move-window -s %%'

I suspect that the approach involves something like the following sequence of operations:

  1. Split window
  2. Choose-window (pane)
  3. join-pane
  4. kill previous pane (the one that held the choose-window prompt)

But, when I try to do something like the following:

split-window -h ; choose-window 'join-pane -hs %%' ; kill-pane -t.-1

The Pane killed is the one I started from, NOT the one used to display the prompt. Indeed, changing the value for kill-pane, or issuing a select-pane first does not seem to make a difference.

Perhaps this cannot be done, perhaps there is a way to move a window/0-pane to a new pane, but I can't figure it out. Perhaps there is some combination of interactive commands and calls to

run "tmux <command> etc etc %%"

That will fix it, but I can't figure it out. Ideas?

3
  • This question may help. It shows a nice way of "zooming" a pane into a full window, then restoring it to its original position, via a temporary window. It's sort of the reverse of what you are attempting, but you may be able to adapt some ideas.
    – chepner
    Sep 5, 2012 at 15:46
  • If I reverse that method (i.e. join-pane and then break-pane) by trying something like this: split-window -h ; choose-window 'join-pane -hs %%' ; break-pane -t.-1 It immediately pushes the current window up by one, and creates a new window behind the current one that contains the full-screen choose-window prompt. Upon selecting, it works identically to the first method I discussed above. Sep 5, 2012 at 19:07
  • This was an awesome question, I had never even thought to try and add prompting for commands that didn't already have it. I added two new bindings into my tmux as a result, one for horizontal and one for vertical. Thank you for asking this and thank you @chris-johnsen
    – Neg_EV
    Sep 10, 2012 at 15:10

1 Answer 1

4

You could kill the initial, temporary pane before join-pane re-splits the window:

bind < split-window -h \; choose-window 'kill-pane ; join-pane -hs %%'
2
  • AHA! That does it! That's the magic sauce of command ordering I was looking for. Well done! Sep 6, 2012 at 20:43
  • Just to finalize, I also have: bind > break-pane -d Which I execute in any split to send it back where it came from (without leaving the current window) Sep 12, 2012 at 21:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .