post

An Easy Method for Copying Text from WSL to the Windows Clipboard

A short snippet to help you copy text from WSL into the Windows Clipboard, replicating the clip behaviour.

Dec 23, 2019 · 1 min read

While the Windows Subsystem for Linux is great, there are some things that don’t quite work easily out of the box. One of those things is copying text to clipboard. For instance, if you were following the Github tutorial for adding an SSH key to an account, you might get stuck at the following line:

clip < ~/.ssh/id_rsa.pub

Clip doesn’t work out of the box with WSL, but here’s a quick way to make it work natively with the Windows clipboard:

function clip() {
  cat $1 | clip.exe
}

Just add this to your ~/.bashrc file and you should be able to run commands like:

clip ~/.ssh/id_rsa.pub

To copy your public key to your Windows Clipboard for pasting into Github or wherever you need it.