Skip to content

Instantly share code, notes, and snippets.

@yudai
Created Nov 29, 2017
Embed
What would you like to do?
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.

@agriffis

This comment has been minimized.

Copy link

@agriffis agriffis commented Feb 5, 2018

Thanks, just finished getting tmux + mosh + hterm (Chrome OS) cooperating with OSC 52, and this was a big help!

@tylerhoran

This comment has been minimized.

Copy link

@tylerhoran tylerhoran commented Jun 15, 2018

@agriffis do you mind sharing your tmux.conf for tmux + mosh + chrome os ?

@agriffis

This comment has been minimized.

Copy link

@agriffis agriffis commented Jul 3, 2018

@tylerhoran Here are the most interesting bits

# tmux-256color instead of screen-256color enables italics
set -g default-terminal "tmux-256color"

# Tc enables true color
set -ag terminal-overrides ",*256col*:colors=256:Tc"

# Ms modifies OSC 52 clipboard handling to work with mosh, see
# https://gist.github.com/yudai/95b20e3da66df1b066531997f982b57b
set -ag terminal-overrides "vte*:XT:Ms=\\E]52;c;%p2%s\\7,xterm*:XT:Ms=\\E]52;c;%p2%s\\7"

# enable OSC 52 clipboard
# https://medium.freecodecamp.org/tmux-in-practice-integration-with-system-clipboard-bcd72c62ff7b
set -g set-clipboard on

# use bracketed paste, if the running application (vim/emacs/weechat) has
# sent the terminal code to enable it.
bind-key ] paste-buffer -p

setw -g aggressive-resize on

# http://comments.gmane.org/gmane.emacs.vim-emulation/1557
set -s escape-time 0
@tylerhoran

This comment has been minimized.

Copy link

@tylerhoran tylerhoran commented Jul 29, 2018

thanks @agriffis!

@gwicke

This comment has been minimized.

Copy link

@gwicke gwicke commented Jul 17, 2019

PR for mosh that avoids the need for custom tmux settings: mobile-shell/mosh#1054

@dasizeman

This comment has been minimized.

Copy link

@dasizeman dasizeman commented Sep 30, 2020

@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

This comment has been minimized.

Copy link

@agriffis agriffis commented Sep 30, 2020

@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/

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