Skip to content

Instantly share code, notes, and snippets.

@yudai
Created November 29, 2017 01:04
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yudai/95b20e3da66df1b066531997f982b57b to your computer and use it in GitHub Desktop.
Save yudai/95b20e3da66df1b066531997f982b57b to your computer and use it in GitHub Desktop.
tmux + mosh OSC 52 clipboard paste hack

Problem

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.

Workaround

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.

@dasizeman
Copy link

@yudai @tylerhoran @agriffis @gwicke Do you know what the minimum mosh version needed for this is? It's not working for me and I wish it did, I would love to get this working without having to build a custom mosh right now (but thanks for your work @gwicke!)

@agriffis
Copy link

@dasizeman There isn't a release of mosh with truecolor support. You need unreleased trunk. mobile-shell/mosh#974

If you're running Fedora, you can use my COPR https://copr.fedorainfracloud.org/coprs/agriffis/mosh-nightly/

@ilyagr
Copy link

ilyagr commented Nov 29, 2022

Alternative PR that claims to improve on the one @gwicke suggested: mobile-shell/mosh#1104

But actually, this seems to be a bug in tmux that is already fixed on the master branch (and thus hopefully in the next release): tmux/tmux#3192

@ipatch
Copy link

ipatch commented May 31, 2023

not sure if the clipboard option was removed or not but running

tmux show-options -g clipboard

yields

invalid option: clipboard

@jaclu
Copy link

jaclu commented Jul 9, 2023

not sure if the clipboard option was removed or not but running

tmux show-options -g clipboard

yields

invalid option: clipboard

You need to do: tmux show-options -g set-clipboard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment