Copy and Paste with Clipper

If you're a Mac user and you're using tmux, do you ever have trouble getting the tmux copy buffer to work with the system clipboard? The widely recommended solution is reattach-to-user-space, which you can install with Homebrew. However, this doesn't help when you also work with remote sessions -- I end up pasting content into a buffer, then using scp to copy it into pbcopy on my Mac. Or fudging it with the mouse and formatting the weird whitespace issues.

Greg Hurrell has created clipper, a Mac daemon that runs in the background and allows you to interact with local and remote clipboards. The documentation explains the need for clipper and how it works, and it also has a snippet you can use with Vim. Incidentally, this solution is based on netcat, which seems like a clever way of keeping the project relatively simple.

The source code is Go, and it's pretty short and readable. The network traffic is over the local loopback interface and SSH, so it does mean that people on your local machine can connect to your clipper instance:

This may be fine on a single-user machine, but when you start using ssh -R to expose your Clipper instance on another machine you're evidently increasing your surface area. This may be ok, but my intention is to add an authentication mechanism to the protocol in the near future in any case.

The combination of a daemon and netcat is a clever way of sidestepping the messy issues of directly interacting with Apple's clipboard API. I haven't yet used it over a network but I do run into this a lot with my tmux/Vim sessions, so I'm looking forward to setting it up.

blog comments powered by Disqus