Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jordangarrison/fa067b5f3f91952076f58a9a44c2b8e7 to your computer and use it in GitHub Desktop.
Save jordangarrison/fa067b5f3f91952076f58a9a44c2b8e7 to your computer and use it in GitHub Desktop.
Requirements for Remote Sharing Clipboard with Terminal Emacs.md

Requirements for Remote Sharing Clipboard with Terminal Emacs

So I use Emacs because it is a great tool and I am productive with it. I also code on a development box to avoid x86=>aarch64 compatibility issues with many things on the Mac. Lastly I use NixOS and the Nix package manager on the dev server and Mac respectively.

Problem - clipboards are hard

So I hit a problem. I hadn't noticed it until I was screen sharing and needed to grab some text from the file I was looking at and paste it into chat. I couldn't. The problem with running on a remote box via the terminal is the clipboard exists on the remote server and not locally.

Solution

I found a solution using something that has been around forever, X11. The workflow is a bit tedious, but definitely scriptable at some point.

First I needed to update my NixOS server to allow X11 forwarding.

{ config, pkgs, ... }:
let
  [...]
in { 
  [...]
  services.xserver.enable = true;
  services.openssh.enable = true;
  services.openssh.forwardX11 = true;
  programs.ssh.forwardX11 = true;
  programs.ssh.setXAuthLocation = true;
  [...]
}

Now that I had this enabled I needed XQartz on the Mac. I attempted this install with Nix but it borked pretty bad so I just downloaded it from the site.

After this I open my terminal and log in to the remote box.

ssh -X user@devbox
emacsclient -nw [path/to/work]

When I copy text in emacs in the terminal it forwards the clipboard to XQuartz and thus the mac.

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