Now tmux, mosh and iTerm2 support the OSC 52 sequence that enables clipboard sharing. However, there is a trap that prevents them from working together.
Mosh accepts OSC 52 sequences with the c;
option. However, tmux doesn't send that option when it emits OSC 52 sequences, which means you cannot use tmux and mosh together with the default configuration.
You can override the OSC 52 sequence generated by tmux by adding the following line to your tmux.conf.
set-option -ag terminal-overrides ",xterm-256color:Ms=\\E]52;c;%p2%s\\7"
Instead of using the default Ms
sequence Ms=\\E]52;%p1%s;%p2%s\\7"
, whose %p1%s;
is the option part, this configuration forces use c;
as the option value.
Note that xterm-256color
must be replaced with your $TERM
value.
For me
set-option -ag terminal-overrides ",xterm-256color:Ms=\\E]52;c%p1%.0s;%p2%s\\7"
works for all tmux versions I have tested down to 1.7. I wouldn't normally run ancient versions just for the fun of it, but since i often test compatibility with tmux plugins, I tend to see how far back a given plugin works.However when testing various versions I came across a pretty annoying cut-paste issue.
If you use asdf to use multiple versions of tmux, be aware that if you start a remote tmux in a folder with a local tmux version, anytime you select something with the tmux buffers, tmux insta-craches! This happens even if the local tmux version is the same as the global one.
You can still use the terminals cut & paste features.
On localhost sessions, using other asdf versions of tmux as local overrides works fine, but on a remote session, be it ssh or mosh, you need to use
set -g set-clipboard off
in order to be able to use the tmux buffers.this is regardless if the OSC 52 fixes mentioned here are used or not.
kind of an odd issue, so perhaps I'm doing something wrong, but disabling tmux clipboard was the only solution I could find.