Is there a way to remove a new line from out-clipboard
or clip
in PowerShell?
I'm using this code to copy current path to clipboard:
function cl() {
(Get-Location).ToString() | clip
}
And every time I use this, a new line is added to the copied text. It's frustrating, because then I can't paste it in the CLI, like I would with text that is copied from elsewhere. Because a new line makes a command on the CLI automatically executed.
Example: I'm in C:\Users
and type cl
, and then I use Alt + SPACE + E + P to pass the text, the command is executed, and I can't type any more. But when text is passed without a new line nothing is executed, and I can continue to type.
Use the Set-Clipboard
function:
(get-location).ToString()|Set-Clipboard
Add-Type -Assembly PresentationCore
$clipText = (get-location).ToString() | Out-String -Stream
[Windows.Clipboard]::SetText($clipText)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With