Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot copy to my system clipboard when I run tmux on a remote server and connect using SSH #119

Open
indrayam opened this issue Nov 23, 2017 · 14 comments

Comments

@indrayam
Copy link

indrayam commented Nov 23, 2017

I am using Oh-My-Tmux on my laptop which is a MacBook running MacOS Sierra. Tmux version is 2.6. I have latest XQuartz installed as well. My /etc/ssh/ssh_config settings have been modified to forward X11:

# XAuthLocation added by XQuartz (http://www.xquartz.org)
Host *
    XAuthLocation /opt/X11/bin/xauth
    ForwardX11 yes

The terminal app I am using is iTerm 2 and I am connecting remotely to an Ubuntu 16.04 droplet on Digital Ocean using the function below. I am running latest Tmux (2.6) on my Ubuntu droplet and have installed xclip (and xsel) as well.:

function ssht () {/usr/bin/ssh -X -t $@ "tmux attach -t development || tmux new -s development";}

To connect, I type:

ssht <ssh-config-alias-for-my-host>

Simple dragging of any text on my remote server using my mouse copies it to the Tmux buffer. I can see them when I run Ctrl + a P. However, they are not getting copied to my Mac's system clipboard.

Any suggestions on what I am doing wrong?

@gpakosz
Copy link
Owner

gpakosz commented Nov 23, 2017

The behavior you're seeing is tmux's normal behavior when mouse mode is on.

If turn mouse mode off, then iTerm2 will handle the selection and pasting to your Mac's clipboard.

If you want to use your mouse to resize or select panes but you don't want it to handle entering in copy mode and selecting text you have to unbind MouseDrag* bindings:

$ tmux list-keys | MouseDrag
bind-key    -T copy-mode    MouseDrag1Pane    select-pane ; send-keys -X begin-selection
bind-key    -T copy-mode    MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"
bind-key    -T copy-mode-vi MouseDrag1Pane    select-pane ; send-keys -X begin-selection
bind-key    -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"
bind-key    -T root         MouseDrag1Pane    if-shell -F -t = "#{mouse_any_flag}" "if -Ft= \"#{pane_in_mode}\" \"copy-mode -M\" \"send-keys -M\"" "copy-mode -M"
bind-key    -T root         MouseDrag1Border  resize-pane -M

@indrayam
Copy link
Author

Wow, that's good to know. Never thought of that. Let me play with it and see if I can unbind the MouseDrag* bindings.

@gpakosz
Copy link
Owner

gpakosz commented Jan 22, 2018

Hello @indrayam,

Are we good?

@indrayam
Copy link
Author

Unfortunately, I decided to move on without diving further into it. My apologies.

@gpakosz
Copy link
Owner

gpakosz commented Mar 6, 2018

Hello @indrayam,

I think the os-clipboard branch will interest you. It's now possible to copy from a remote machine to the local system clipboard.

Here are the pre-requisites:

  • have a remote machine configured to use the os-clipboard branch of this configuration
  • have tmux_conf_copy_to_os_clipboard=true (in ~/.tmux.conf.local) on that remote machine

Now,

  • ssh into the remote server
  • launch tmux there, or attach to a session
  • enter copy mode then copy some text (using your copy-selection bindings)
  • what you copied on the remote side is now in your local clipboard

@amioranza
Copy link

I don't know if mac terminal works like linux one but one simple solution to me is keep SHIFT key pressed when I select what I want to copy, use the right button to copy and it sends the content to the clipboard,

@haoransh
Copy link

@amioranza Just a supplement. On mac, keep the option key instead of SHIFT key when selecting. Also, use command+v to paste.

@anjos
Copy link

anjos commented Oct 16, 2018

@haoransh: On my current setup, it works if I set the remote tmux with mouse on and use "SHIFT+CMD" together with the mouse (left button) to copy to the local clipboard (using iTerm2). Not sure this is by design or simply luck...

@zkanda
Copy link

zkanda commented Jan 31, 2019

@gpakosz I used the os-clipboard and it works like a charm, any chance we can merge it to master? :)

@diego898
Copy link

Just checking up on this, I'd like to be able to 1. Select things in a pane like "normal" (mouse mode on), and ahve things show up in both the tmux paste buffer, as well as in my mac clipboard for pasting. Thanks!

@notrev
Copy link

notrev commented Mar 27, 2019

Any plans on having this merged to master branch?

@gpakosz
Copy link
Owner

gpakosz commented Mar 27, 2019

Hello @notrev,

Merging the branch requires requiring tmux >= 2.4 instead of >= 2.1. That may be the right time

@yankee14
Copy link

I don't know if mac terminal works like linux one but one simple solution to me is keep SHIFT key pressed when I select what I want to copy, use the right button to copy and it sends the content to the clipboard,

This works unless I have a window split vertically, i.e. two panes side by side. Selecting with the shift key causes the selection to sort of "bleed" into the next pane, and the text that gets copied has lots of garbage in it, including pipe symbols '|' where the pane bled into the next pane.

@dyxushuai
Copy link

Can this work with mouse?
I find I cannot copy text from my ssh tmux session which is over my local tmux session

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

No branches or pull requests

10 participants