I launch multipane tmux window to monitor several server parameters.
With Ctrl-S I can open a new window with another monitor command.
Now I want to bind Ctrl-Q to open another multipane window with several monitors. How do I bind a key to multiple commands?
I tried chaining them with ; and \; – nothing helps. Please, advise what should I use instead of … below.
Is it possible when I open a new window to suspend the background commands overlapped by it?
tmux new-session "monitor1" \;\
split-window -v "monitor2" \;\
select-pane -U \;\
split-window -v -h -p 60 "monitor3" \;\
bind-key -n C-s new-window "monitor4" \;\
bind-key -n C-q "..."
Best Answer
Todd Freed is right, the "correct" way to do this is using
\;
. Sort of. But there's a snag.You see, you join a sequence of tmux commands together by giving tmux the conjunction
;
. Thus, in a file sourced by tmux, you might sayif, for some reason, you wanted that all on one line. Now, you can give that one-line compound statement to the
tmux
command from a shell also but the;
must be escaped so that the shell interprets it as another argument fortmux
. Thus the equivalent of the above from the shell isSimilarly, the tmux
bind-key
command takes a series of arguments which are the tmux command and arguments to run when the key is pressed. If you wanted to bindC-q
to the above sequence from inside a file sourced by tmux, you'd sayHere we've escaped the
;
from tmux, so that tmux doesn't interpret it as the end of thebind-key
command, but as another argument tobind-key
telling it to form a compound command as the bound value of theC-q
key.So what happens when we want to make tmux do that from the shell? A whole lot of escaping.
First, we have to escape the
\
and the;
each from the shell, causing the shell to pass the two characters\;
as an argument totmux
. This then escapes the;
from tmux, causing it to assign the entire compound statement as the binding ofC-q
.Now, all that said, if you use a complex tmux setup like this repeatedly, I'd suggest that you create a tmux file to keep it in:
And then:
It'll be a lot easier to maintain that way.