learntmux.dev

Break out, join and send keys

Goal

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 window at C-b :
pull a pane from another window into this one
send-keys -t target text Enter at C-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.

Do this

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.

Stuck on this one?

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

about 15 MB, once

session learn

Done when

not started
  1. The tail pane now lives alone in window 2— not done yet
  2. Window 1 is gone and window 0 has two panes— not done yet
  3. send-keys ran echo joined-ok in the joined pane— not done yet