Tmux: Prompt to select window for join-pane while still seeing window numbers and titles


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?

Best Answer

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 %%'