brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: set -g allow-passthrough on lets escape codes in a pane reach your terminal

Tmux
~/tips/tip-tmux-allow-passthrough

set -g allow-passthrough on

Lets programs inside tmux send terminal-specific escape codes, such as iTerm2's, past tmux.

tmux sits between your programs and your terminal, and it drops escape sequences it does not understand. That is safe, but it also blocks the special codes of terminals like iTerm2. Passthrough is the way around it.

A program wraps the code in a special DCS sequence that starts with tmux;, and doubles every ESC inside it. Since tmux 3.3 that only works when the option is on:

set -g allow-passthrough on

allow-passthrough is a pane option, and -g makes it the default for every pane. on passes the codes only while the pane is visible. all also lets panes you can’t see through.

A small example sets an iTerm2 mark from inside tmux, so you can jump back to that spot in iTerm2 later:

printf '\033Ptmux;\033\033]1337;SetMark\007\033\\'

With the option off, tmux swallows the whole thing and iTerm2 never sees it. With it on, iTerm2 gets the plain ESC ] 1337;SetMark code. Some tools that print images or change terminal settings from inside tmux use the same trick; their README says when they need this option.

The tmux FAQ warns that tmux does not know what such a code changed in the terminal, so tmux may undo it. There is a second reason to be careful: with passthrough on, any program in a pane can talk to your terminal directly, including a cat of a file you did not write. I’d use on and not all, and only when a tool needs it.

Further reading: tmux manual page (OpenBSD), tmux wiki: FAQ, the passthrough escape sequence

More Tmux tips tmux new -d -s report -x 200 -y 50 'top' tmux wait-for build-done tmux kill-server Ctrl-b [ tmux new -s scratch \; set destroy-unattached on All Tmux tips (125) All topics

Link