3

My dream: From my osx machine I ssh to a linux machine and can copy paste with a commandline application like xclip or pbcopy, and then be able to use it on my host machine.

Example input

(mac)$ ssh -X linux_mach
(lin)$ echo "heyyy" | pbcopy
(lin)$ any_other_command
(lin)$ exit
(mac)$ pbpaste 
heyyy

I've seen many answer about how to do it from osx to osx or from linux to linux. However, I'm not able to put together these answer to get it to work across different systems, even if I enable X11 forwarding.

The reason I want to be able to do it with an commandline application is because i then plan on infusing this into my tmux+vim session, which i'm already able to do when i run the tmux session locally.

The closest I've gotten to get this working can be found at this url: http://seancoates.com/blogs/remote-pbcopy

1

There is a simple solution to your problem. I do exactly what you want to do all the time.

Your first step should be to start tmux in your steps above. However, you should include the following in your tmux configuration, .tmux.conf file, to bind the appropriate chords to pbcopy and pbpaste.

I've included an example .tmux.conf configuration section of copy/paste integration for macos, (linux would xclip or other linux kill-ring integration).

# copy-paste integration
set-option -g default-command "login-shell"

# use vim key bindings in copy mode
setw -g mode-keys vi

# use 'v' to begin selection like in vim
bind-key -t vi-copy v begin-selection
bind-key -t vi-copy y copy-pipe "pbcopy"

# update default bindings of `Enter` to also use copy-pipe
unbind -t vi-copy Enter
bind-key -t vi-copy Enter copy-pipe "pbcopy"

# bind ']' to use pbpaste
bind ] run "pbpaste | tmux load-buffer - && tmux paste-buffer"

Then you have several options at your disposal when ssh'd into a remote server.

  1. you may copy text by highlighting it and before release your mouse, type y to copy the text to your local mac clipboard
  2. to paste the text, simply use the chord cmd-v (it doesn't matter if you are local or remote)
  3. use the tmux chord, <prefix>,[ or ctrl-a,[ in my case to enter tmux copy mode
    • Begin copy selection with v and once the text is highlighted, copy it with y

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.