Break out, join and send keys
tail alone in window 2, the shell pane joined into window 0, and joined-ok printed there.
Panes are not stuck in the window they were born in:
C-b !- break the active pane out into a window of its own
join-pane -s windowatC-b :- pull a pane from another window into this one
send-keys -t target text EnteratC-b :- type into a pane you are not even looking at
A pane keeps its program and its history when it moves. Joining the last pane out of a window closes that window, exactly as killing it would.
Targets are written session:window.pane — learn:0.1 is pane 1 of window 0 in session learn.
With the tail pane active, press C-b !.
It becomes window 2; window 0 has one pane left.
Press C-b 0, then C-b :, type join-pane -s shell, Enter.
Window 0 has two panes and window 1 is gone.
Press C-b :, type send-keys -t learn:0.1 'echo joined-ok' Enter, Enter.
joined-ok prints in the second pane.
How send-keys reads arguments
send-keys sends each argument as keys: a quoted string is typed out literally, and a key name like Enter is pressed as that key. That is why the command and the Enter are two separate arguments.
Here is what just happened.
break-pane gave the tail pane a new window at the next free index. join-pane moved shell’s only pane here, so the empty window closed. send-keys delivered the text and then the Enter key to pane 1, which ran it as if you had typed it.
- Move the active pane into a new windowC-bthen!
- Move a pane from another window into the current window as a new pane:join-pane -s src
- Send keystrokes to a pane, for example a command followed by Enter:send-keys -t target keys
Go further
join-pane -hor-vchooses how the incoming pane splits;-tpicks a destination other than the current window.break-pane -n namenames the new window.capture-pane,pipe-pane,respawn-paneanddisplay-menuare the next scripting tools to read about inman tmux.
- 1
join-pane -s shellnames the source; the destination is the window you run it from. Be in window 0. - 2
C-b !on thetailpane breaks it out. ThenC-b 0,C-b :,join-pane -s shell. - 3
send-keys -t learn:0.1 'echo joined-ok' Entertypes into pane 1 of window 0 from the prompt.
This is a live terminal. Typing goes to the machine, including Tab. Press Shift and Tab together to move focus back out to the page.
A real terminal, in this tab
Alpine Linux and tmux 3.4 on an x86 emulator. Nothing to install, and no server behind it.
about 15 MB, once
Done when
not started- The tail pane now lives alone in window 2— not done yet
- Window 1 is gone and window 0 has two panes— not done yet
- send-keys ran echo joined-ok in the joined pane— not done yet