brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Set-Clipboard copies command output from the PowerShell terminal

Terminal
~/tips/tip-terminal-set-clipboard-powershell

Get-Content $HOME\.ssh\id_ed25519.pub | Set-Clipboard

Sends the result of any PowerShell command straight to the clipboard.

Selecting output with the mouse and hoping you got every line is fiddly. PowerShell can put it on the clipboard for you.

Pipe anything into Set-Clipboard, or scb for short:

Get-Content $HOME\.ssh\id_ed25519.pub | Set-Clipboard
Get-Process | Sort-Object CPU -Descending | Select-Object -First 5 | Out-String | Set-Clipboard

The first is the classic: copying a public key to paste into a web form. The second shows a detail: objects are turned into text first. Without Out-String you get only the default string of each object, which for many types is just the type name, so I’d add it whenever the output is a table.

-Append adds to what is already on the clipboard instead of replacing it, which helps when you collect bits from a few commands. The way back is Get-Clipboard, which hands you the clipboard as lines you can pipe on.

Over SSH there is a twist. Set-Clipboard then fills the clipboard of the remote machine, which is rarely what you want. PowerShell 7.4 added -AsOSC52, which uses an escape sequence to set the clipboard of the computer you are sitting at. That only works if your terminal supports OSC 52; Windows Terminal does.

Further reading: Set-Clipboard (Microsoft Learn)

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}' All Terminal tips (116) All topics

Link