-
Notifications
You must be signed in to change notification settings - Fork 852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Copying and pasting from system clipboard using something like xclip #1069
Comments
Hi @brandonpollack23 -- good point; this would be useful. I wonder if xclip can be made to work if you install an X server and configure WSL to use it: http://wsl-forum.qztc.io/viewtopic.php?f=6&t=14 |
I can confirm that having Xming running and configuring the $ export DISPLAY=:0
$ echo 'some text' | xclip -selection clipboard This works just fine. Apparently using the Can't say for sure about the other X implementations, though, but I think redirecting the X clipboard to the windows clipboard is the natural thing to do for any X windows implementation. |
Xming does indeed work, but I'd like to suggest that the need to support "the home OS [ie Windows] clipboard" without X11 is still valid. It's arguably a gross hack, but the cygwin method of "/dev/clipboard" to read and write the system clipboard would be very groovy. |
+1 |
+10! Something like Cygwin's /dev/clipboard would be great but something as simple as OS X's pbcopy and pbpaste would be plenty. |
In recent insider builds, WSL has been able to access Windows binaries. Thanks to this, you can use |
@mogest I tried this with vim-fakeclip but it can only write and not read. A workaround is to use PowerShell but that's really slow (it takes 1-2 seconds for |
Hey Guys! |
|
is anyone working on this? |
Just to clarify for anyone who stumbles upon this thread, to use type |
I am not sure how update-to-date this is. But "clip.exe" is not working for me... |
@HiImJulien Just tested it, still works. Maybe it's the version of WSL you are running? |
@HiImJulien Try typing |
The OP here didn't really lay out a well defined ask. There is no clipboard in Linux outside of the context of X11 (or another windowing system). If you run |
@therealkenc |
A limitation that is most unfortunate. And unrelated to WSL. You can paste with right-click of course. But you made me curious enough (just) to do a search. [ed: Get-Clipboard. It's late 😴.]
Using backticks ( |
xclip on Linux is great because you can pipe to/from it. WSL could support something similar for the Windows clipboard.
|
WSL could not; because the Windows clipboard is not in WSL. That said the win32 team could add a paste feature to
Faster than typing, anyway 😉. |
@laktak I tried it. Apparently my WSL was broken, after I changed the my home directory to I am just curious. Why is |
That is #2003. |
Before I take this issue off-topic: 'clip.exe' is special, since it is basically a gateway between the WSL and the Host (unless I can install 'xclip' or 'pbcopy' inside WSL and still have it work). |
No, it is a win32 program that calls win32 api functions. Just like every other |
@therealkenc Thanks for you solution, but each time I use
|
Not sure what version you are running, but I was seeing borkage like that with copy/paste in general for a period around the Fall Update. I noticed it whenever I copy/pasted from my shell into github posts in my browser; nothing to do with WSL. Problem was not specific to It seemed to have cleared up somewhere along the way, because my pastes have been fine "lately". I just tried your repro on 18305 and it seems to work correctly without the extra newline. I couldn't tell you what versions were/are affected exactly, and I don't have a 17763 (RS5) handy atm to test. You might check over in the console tracker and see if they know anything about it. |
Don't know if anything has hit Preview Ring yet. 17763 is just bog standard 1809 aka RS5 aka 2018 Fall Update. Yes I'm on Fast Ring. I wouldn't sweat the Fast Ring unless this is something critical to your workflow. |
OK, thanks again. |
|
Adding to this, you can just
Works for simple use cases which is all I use it for :) |
Here's what I've been doing: (note this includes fixes suggested below!) alias pbcopy='clip.exe'
alias pbpaste="powershell.exe -command 'Get-Clipboard' | tr -d '\r' | head -n -1" The first one just aliases Hope that's helpful. This is from the following: https://effective-shell.com/docs/part-1-transitioning-to-the-shell/4-clipboard-gymnastics/ Would love to see a "more native" solution like |
@dwmkerr solution for
|
Oh nice @walbertus that's much cleaner, updated my earlier comment! |
I tried to use the I think that real problem is the new-line definition between Windows and Linux. Windows adds return-carry (\r) then when text is paste in terminal contain \r\n instead of only \n. I changed
|
@adrianmusante the paste command still seems to add an extra trailing newline: $ printf 'foo\nbar\n'
foo
bar
$ printf 'foo\nbar\n' | xxd
00000000: 666f 6f0a 6261 720a foo.bar.
$ printf 'foo\nbar\n' | pbcopy
$ pbpaste
foo
bar
$ pbpaste | xxd
00000000: 666f 6f0a 6261 720a 0a foo.bar.. You can tell the source of the issue is the paste command and not the copy command by pasting into your editor. It looks like we still need alias pbcopy='clip.exe'
alias pbpaste="powershell.exe -command 'Get-Clipboard' | tr -d '\r' | head -n -1" $ printf 'foo\nbar\n'
foo
bar
$ printf 'foo\nbar\n' | xxd
00000000: 666f 6f0a 6261 720a foo.bar.
$ printf 'foo\nbar\n' | pbcopy
$ pbpaste
foo
bar
$ pbpaste | xxd
00000000: 666f 6f0a 6261 720a foo.bar. |
Awesome, updated my original comment! |
I solved this for me by adding this in my .tmux.conf
|
this worked for me as well. OS: WSL 1 (Ubuntu) |
In an application like neovim, you can use xclip as a clipboard provider (you can also use xclip in general which is useful) to copy and paste from the system clipboard. As there is no X server here, and windows is the shell, it'd be great if we had an alternative.
a version of xclip running that messages to the windows shell for copy/paste would be amazing.
I am running the latest consumer release of RS
probobly not useful but here is a strace of xclip
execve("/usr/bin/xclip", ["xclip"], [/* 24 vars */]) = 0
brk(0) = 0x12c8000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f7a4afd0000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=40023, ...}) = 0
mmap(NULL, 40023, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f7a4afd6000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/libXmu.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\200g\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=103016, ...}) = 0
mmap(NULL, 2199416, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f7a4a9e0000
mprotect(0x7f7a4a9f8000, 2093056, PROT_NONE) = 0
mmap(0x7f7a4abf7000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17000) = 0x7f7a4abf7000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/libX11.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\360\207\1\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=1265072, ...}) = 0
mmap(NULL, 3362112, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f7a4a6a0000
mprotect(0x7f7a4a7d0000, 2097152, PROT_NONE) = 0
mmap(0x7f7a4a9d0000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x130000) = 0x7f7a4a9d0000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P \2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1840928, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f7a4afc0000
mmap(NULL, 3949248, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f7a4a2d0000
mprotect(0x7f7a4a48a000, 2097152, PROT_NONE) = 0
mmap(0x7f7a4a68a000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1ba000) = 0x7f7a4a68a000
mmap(0x7f7a4a690000, 17088, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f7a4a690000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/libXt.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\2601\1\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=413232, ...}) = 0
mmap(NULL, 2511648, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f7a4a060000
mprotect(0x7f7a4a0bf000, 2097152, PROT_NONE) = 0
mmap(0x7f7a4a2bf000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x5f000) = 0x7f7a4a2bf000
mmap(0x7f7a4a2c5000, 800, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f7a4a2c5000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/libXext.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\2005\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=73288, ...}) = 0
mmap(NULL, 2169048, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f7a49e40000
mprotect(0x7f7a49e51000, 2093056, PROT_NONE) = 0
mmap(0x7f7a4a050000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x10000) = 0x7f7a4a050000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/libxcb.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 \226\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=125392, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f7a4afb0000
mmap(NULL, 2220648, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f7a49c20000
mprotect(0x7f7a49c3d000, 2097152, PROT_NONE) = 0
mmap(0x7f7a49e3d000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1d000) = 0x7f7a49e3d000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\320\16\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=14664, ...}) = 0
mmap(NULL, 2109744, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f7a49a10000
mprotect(0x7f7a49a13000, 2093056, PROT_NONE) = 0
mmap(0x7f7a49c12000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f7a49c12000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/libSM.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\340\33\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=30896, ...}) = 0
mmap(NULL, 2126160, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f7a49800000
mprotect(0x7f7a49807000, 2093056, PROT_NONE) = 0
mmap(0x7f7a49a06000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0x7f7a49a06000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/libICE.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260N\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=98288, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f7a4afa0000
mmap(NULL, 2208000, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f7a495e0000
mprotect(0x7f7a495f7000, 2093056, PROT_NONE) = 0
mmap(0x7f7a497f6000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x16000) = 0x7f7a497f6000
mmap(0x7f7a497f8000, 12544, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f7a497f8000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/libXau.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\16\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=14456, ...}) = 0
mmap(NULL, 2109720, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f7a493d0000
mprotect(0x7f7a493d2000, 2097152, PROT_NONE) = 0
mmap(0x7f7a495d2000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f7a495d2000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/libXdmcp.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\23\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=22616, ...}) = 0
mmap(NULL, 2117856, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f7a491c0000
mprotect(0x7f7a491c5000, 2093056, PROT_NONE) = 0
mmap(0x7f7a493c4000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x4000) = 0x7f7a493c4000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libuuid.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`\26\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=18936, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f7a4af90000
mmap(NULL, 2113968, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f7a48fb0000
mprotect(0x7f7a48fb4000, 2093056, PROT_NONE) = 0
mmap(0x7f7a491b3000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3000) = 0x7f7a491b3000
close(3) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f7a4af80000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f7a4af70000
arch_prctl(ARCH_SET_FS, 0x7f7a4af70780) = 0
mprotect(0x7f7a4a68a000, 16384, PROT_READ) = 0
mprotect(0x7f7a491b3000, 4096, PROT_READ) = 0
mprotect(0x7f7a493c4000, 4096, PROT_READ) = 0
mprotect(0x7f7a495d2000, 4096, PROT_READ) = 0
mprotect(0x7f7a497f6000, 4096, PROT_READ) = 0
mprotect(0x7f7a49a06000, 4096, PROT_READ) = 0
mprotect(0x7f7a49c12000, 4096, PROT_READ) = 0
mprotect(0x7f7a49e3d000, 4096, PROT_READ) = 0
mprotect(0x7f7a4a9d0000, 4096, PROT_READ) = 0
mprotect(0x7f7a4a050000, 4096, PROT_READ) = 0
mprotect(0x7f7a4a2bf000, 4096, PROT_READ) = 0
mprotect(0x7f7a4abf7000, 4096, PROT_READ) = 0
mprotect(0x604000, 4096, PROT_READ) = 0
mprotect(0x7f7a4ae22000, 4096, PROT_READ) = 0
munmap(0x7f7a4afd6000, 40023) = 0
brk(0) = 0x12c8000
brk(0x12e9000) = 0x12e9000
write(2, "Error: Can't open display: (null"..., 34Error: Can't open display: (null)
) = 34
exit_group(1) = ?
+++ exited with 1 +++
xclip is needeed for this so sudo apt install xclip
The text was updated successfully, but these errors were encountered: