Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Copy and cut commands don't work on pwsh on WSL2 Ubuntu #1993
Comments
|
I believe this is caused here: https://github.com/PowerShell/PSReadLine/blob/v2.1.0/PSReadLine/Clipboard.cs#L72-L82 On my WSL Ubuntu, the following returns true: I have no
I wonder if this is sufficient to disambiguate? |
|
I offer this as a workaround:
I don't have a way to avoid the trailing newline chars. |
|
This may be a better workaround. Create #!/bin/sh
# https://github.com/PowerShell/PSReadLine/issues/1993
# this is not an xclip replacement! It does just enough to let PSReadline work on WSL.
if [ "$3" = "-out" ]; then
# paste
if command -v pwsh.exe >/dev/null 2>&1; then
pwsh="pwsh.exe"
elif command -v powershell.exe >/dev/null 2>&1; then
pwsh="powershell.exe"
else
exit 1
fi
pwsh="$pwsh -NoProfile -NoLogo -NonInteractive"
$pwsh -command Get-Clipboard | sed 's/\r$//' | head -c -1
exit 0
else
# cut or copy
tee <&0 | clip.exe
exit 0
fiFor reasons I don't understand, it doesn't suffer from the annoying trailing newline that clip.exe normally appends. |
Environment
I am using Windows Terminal.
Steps to reproduce
Set-PSReadlineKeyHandler -Chord Ctrl+c -Function CopyOrCancelLineSet-PSReadlineKeyHandler -Chord Ctrl+x -Function CutExpected behavior
Select text. Ctrl-C or Ctrl-X should place that text on the system clipboard. It should be possible to paste that text in the same WSL terminal or anywhere in the Windows system.
Actual behavior
Text is not placed on the clipboard. Paste, even in the same console, is still pasting the previous clipboard contents.