ssh + tmux + (mouse on) + select_copy_enter, copies to remote clipboard instead of host clipboard

285 views
Skip to first unread message

Sumonto Ghosh

unread,
Feb 25, 2016, 9:28:06 PM2/25/16
to tmux-...@googlegroups.com
Hi,
Currently if I try to copy from iTerm using the mouse + enter method.
The buffer is copied to the remote OS X machine's clipboard instead of the MacBooks clipboard
Appreciate help :)

My settings:
Remote Server: OS X
Local Machine: MacBook

Brew Install
brew install reattach-to-user-namespace

TMux settings: (version 2.1)
# Set TMux Copy mode to vi
set-window-option -g mode-keys vi

# Enable Mouse
set -g mouse on

# Set Smooth Scrolling in Tmux-copy mode
bind-key -t vi-copy WheelUpPane scroll-up
bind-key -t vi-copy WheelDownPane scroll-down

# Copying to OS X clipboard
# Install 'brew install reattach-to-user-namespace'
# Update default binding of `Enter` to also use copy-pipe
# Setup 'v' to begin selection as in Vim
bind-key -t vi-copy v begin-selection
bind-key -t vi-copy y copy-pipe "reattach-to-user-namespace pbcopy"

# Update default binding of `Enter` to also use copy-pipe
unbind -t vi-copy Enter
bind-key -t vi-copy Enter copy-pipe "reattach-to-user-namespace pbcopy"

Suraj N. Kurapati

unread,
Feb 25, 2016, 11:58:11 PM2/25/16
to Sumonto Ghosh, tmux-...@googlegroups.com
On Thu, 25 Feb 2016 18:28:05 -0800, Sumonto Ghosh wrote:
> The buffer is copied to the remote OS X machine's clipboard instead
>
> bind-key -t vi-copy y copy-pipe "reattach-to-user-namespace pbcopy"

That is correct. tmux executes your copy-pipe command successfully,
but it does so on the *remote* machine that hosts your tmux session.

To understand why that setup is insufficient to affect your *client*
machine's clipboard, run "date | reattach-to-user-namespace pbcopy"
inside a brand new SSH session *without* attach tmux. Now, does
your client machine's clipboard contain the current date and time?

No? If you telephoned a friend who lives in a different city and
instructed them to cook dinner, would you expect the resulting meal
appear on your dinner table or theirs? Why, on *theirs*, of course!

The only way for the resulting meal to appear on *your* dinner table
is for it to be transported there. Thus, you need a way to somehow
transport your text selection from the remote machine to your client
machine *before* you attempt to copy it to your client's clipboard.

One unobtrusive way to do this is to use the OSC-52 escape sequence:

http://sunaku.github.io/tmux-yank-osc52.html

I don't know whether iTerm2 obeys the OSC-52 escape sequence; I've
only used it successfully under ChromeOS (hterm) and Linux (xterm).

Cheers.
Reply all
Reply to author
Forward
0 new messages