tmux limits the dimensions of a window to the smallest of each dimension across all the sessions to which the window is attached. If it did not do this there would be no sensible way to display the whole window area for all the attached clients.
The easiest thing to do is to detach any other clients from the sessions when you attach:
tmux attach -d
Alternately, you can move any other clients to a different session before attaching to the session:
takeover() {
# create a temporary session that displays the "how to go back" message
tmp='takeover temp session'
if ! tmux has-session -t "$tmp"; then
tmux new-session -d -s "$tmp"
tmux set-option -t "$tmp" set-remain-on-exit on
tmux new-window -kt "$tmp":0 \
'echo "Use Prefix + L (i.e. ^B L) to return to session."'
fi
# switch any clients attached to the target session to the temp session
session="$1"
for client in $(tmux list-clients -t "$session" | cut -f 1 -d :); do
tmux switch-client -c "$client" -t "$tmp"
done
# attach to the target session
tmux attach -t "$session"
}
takeover 'original session' # or the session number if you do not name sessions
The screen will shrink again if a smaller client switches to the session.
There is also a variation where you only "take over" the window (link the window into a new session, set aggressive-resize
, and switch any other sessions that have that window active to some other window), but it is harder to script in the general case (and different to “exit” since you would want to unlink the window or kill the session instead of just detaching from the session).
The send-prefix
command can be used to send your prefix keystroke to (the process running in) the active pane. By default, the prefix is C-b and C-b is bound to send-prefix
(so that hitting it twice sends a single C-b to the active pane). This is just what we need to access the bindings of the inner tmux instance.
The first C-b is captured by the “outer” tmux instance as its prefix key. The second one is captured by the “outer” tmux instance and triggers its C-b binding (send-prefix
). This sends a C-b to the outer instance’s active pane. The process running in this pane is (ultimately, through an ssh instance) the “inner” tmux instance. It captures the C-b as its prefix key. Now your next keystroke will be passed through the outer tmux instance and captured by the inner one to trigger a binding.
To trigger the c binding (new-window
) in a second-level instance of tmux, you would type C-b C-b c. For a third-level instance of tmux you would type C-b C-b C-b C-b c.
This doubling for each level can be annoying if you are commonly dealing with multiple layers of tmux. If you can spare some other key, you could make a non-prefixed binding to make things (possibly) easier to type:
bind-key -n C-\ send-prefix
bind-key -n C-^ send-prefix \; send-prefix
Create new window in second-level tmux: C-\ c
Create new window in third-level tmux: C-^ c (or C-\ C-\ c)
If you have a limited number of tmux commands that you want to (easily) send to the lower-level tmux instances, you might instead use send-keys
to create some specific bindings (possibly just in your top-level tmux instance):
bind-key C-c send-keys C-b c
bind-key C send-keys C-b C-b c
Create new window in second-level tmux: C-b C-c
Create new window in third-level tmux: C-b C
Best Answer
Unbelievable. I searched everywhere for an answer on the web and I could not find it. Apparently it is just:
tmux send-keys -t Test:Test1 "TEST" C-m