Windows WSL Ubuntu -> Copy to clipboard not working
When trying to copy lines im getting the following error:
error: Unable to copy to clipboard. Make sure xclip or pbcopy is installed.
It is installed though.
➜ apt list --installed | grep xclip
xclip/xenial,now 0.12+svn84-4 amd64 [installed]
However that doesn't work on WSL - when trying it in the command line you will get the following error:
➜ cat .vimrc| xclip
Error: Can't open display: (null)
Which is why i aliased alias clip='clip.exe' and alias xclip='clip.exe'.
xclip not working on ubuntu WSL is not a lnav issue, but what im asking is if maybe we could get windows wsl support or maybe someone knows a way around this issue? :)
With lnav 0.11.1 and WSL2 I'm getting
info: Wrote 1 rows to /dev/clipboard
But /dev/clipboard doesn't exist and nothing gets copied. According to https://www.raymondcamden.com/2017/10/19/copying-to-clipboard-with-windows-subsystem-for-linux clip.exe should be used for clipboard on WSL. I tested using echo 'foo' | clip.exe and it works also on WSL2.
How to configure lnav to use clip.exe on WSL2?
/dev/clipboard is a special name recognized by lnav, it doesn't need to exist in the file system. You can run lnav with the -d option to write out a debug log (e.g. lnav -d /tmp/lnav-debug.log). In the debug log, you should see messages from the "sysclip.cc" file detailing what it has figure out. For example, the following is what happens on MacOS:
2023-02-03T08:41:55.153 D t0 sysclip.cc:59 testing clipboard impl MacOS using: command -v pbcopy > /dev/null 2>&1
2023-02-03T08:41:55.161 I t0 sysclip.cc:61 detected clipboard: MacOS
2023-02-03T08:41:55.161 D t0 sysclip.cc:152 trying detected clipboard command: pbcopy > /dev/null 2>&1
The clipboard configuration is specified here -- https://github.com/tstack/lnav/blob/be42ebf6864ce368403c6406ebf5311f7bf2d79d/src/root-config.json#L26-L74
lnav will go through each type of clipboard and run the test command and use the first that succeeds. The lnav config can be tweaked or we can figure something else out. Please post back what the log says about clipboard discovery.
Hi @tstack! Thanks for looking into it.
I gathered the debug logs and this is what I got:
2023-02-03T19:42:02.904 D t0 sysclip.cc:57 testing clipboard impl MacOS using: command -v pbcopy > /dev/null 2>&1
2023-02-03T19:42:02.943 D t0 sysclip.cc:57 testing clipboard impl NeoVim using: command -v win32yank.exe > /dev/null 2>&1
2023-02-03T19:42:02.981 D t0 sysclip.cc:57 testing clipboard impl Wayland using: test -n "$WAYLAND_DISPLAY" > /dev/null 2>&1
2023-02-03T19:42:02.981 I t0 sysclip.cc:61 detected clipboard: Wayland
2023-02-03T19:42:02.981 D t0 sysclip.cc:152 trying detected clipboard command: wl-copy --foreground --type text/plain > /dev/null 2>&1
I also executed:
echo $WAYLAND_DISPLAY
And the output is wayland-0 but I don't have wl-copy anywhere in the system
BTW. While trying to execute command :config /tuning/clipboard/impls/Windows/test true I got lnav to crash. Here's what I did:
-
lnav -d ./lnav-debug.log - start typing
:config /tuning/clipboard/impls/Wafter the last W i got distracted and paused writing for a few seconds -
lnavcrashed with
:config /tuning/clipboard/impls/wline_ready: write failed: Broken pipe
fish: Job 1, 'lnav' terminated by signal SIGSEGV (Address boundary error)

Should I open a new issue for this?
I created the new issue, thanks for the report. It's probably something in the interactive prompt that is crashing.
It looks like the Wayland impl is being tested first, so maybe set it to false by running this in the shell:
$ lnav -Nn -c ':config /tuning/clipboard/impls/Wayland/test false'
It worked! Thanks!
Working WSL clipboard example, Windows 10 and lnav 0.12.1.
Create ~/.lnav/configs/installed/wsl_clipboard.json with the following content:
{
"$schema": "https://lnav.org/schemas/config-v1.schema.json",
"tuning": {
"clipboard": {
"impls": {
"Wayland": {
"test": false
},
"WSL": {
"test": "command -v /mnt/c/Windows/System32/clip.exe",
"general": {
"write": "/mnt/c/Windows/System32/clip.exe"
}
}
}
}
}
}
This disables the Wayland test/implementation and adds a new clipboard implementation pointing to Windows clip.exe.
(I'm using the full path to the clip executable because I have have appendWindowsPath = false in wsl.conf for performance reasons)