Skip to content

Instantly share code, notes, and snippets.

@yudai
Created November 29, 2017 01:04
Show Gist options
  • 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.

@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

@mellery451
Copy link

warning that this seems to break osc52 with tmux 3.4 which has added some additional OSC features/support

@popjdh
Copy link

popjdh commented Aug 16, 2024

set-option -ag terminal-overrides ",xterm-256color:Ms=\\E]52;c;%p1%s%p2%s\\7" is ok in tmux 3.4. But I dont find any description about %p1%s , It seems that no content is generated by default.

Updated on August 24th
According to tmux#4081, set-option -ag terminal-overrides ",xterm-256color:Ms=\\E]52;c%p1%.0s;%p2%s\\7" should be a better choice. @syu-id

@syu-id
Copy link

syu-id commented Aug 18, 2024

set-option -ag terminal-overrides ",xterm-256color:Ms=\\E]52;c;%p1%s%p2%s\\7" is ok in tmux 3.4. But I dont find any description about %p1%s , It seems that no content is generated by default.

Thanks @popjdh! This works for both tmux 3.4 and 3.3a on my machines.

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