Some Bits: Nelson's log

WSL copy/paste clipboard

Useful command line pipeline tools for WSL, similar to MacOS pbcopy and pbpaste.

To paste the contents of the Windows clipboard into a WSL shell pipeline

powershell.exe Get-Clipboard | wc

To put the outputs of a command into the clipboard

echo foo | clip.exe

That’s the basic version. There’s a nicer version described here or packaged here suitable for installing. It uses sed to strip the DOS newlines and extra newline out of the clipboard content. Also uses tee in front of clip.exe, I think so that it will echo the output back to stdout as well.

Pretty clumsy having to invoke this code! But I believe WSL 2 has no API for accessing the Windows clipboard. It’d be simple enough to imagine in WSL 1’s emulator, but since WSL 2 is more of a VM approach it’d be more work. And then it’d be some weird WSL system call no other Linux understood, anyway. Although... WSL-G must have clipboard support, I wonder if there’s an alternate approach.