Elektrine lite

← Feed

@ddrake@mathstodon.xyz

2026-09-21 09:33 UTC

A fun and useful shell trick: you can, effectively, pipe things from a remote computer into your local clipboard. Context: you're ssh'ed into a remote computer. Locally, you could pipe stuff to xclip or wl-copy or pbcopy to put it in your OS clipboard -- but that won't work in ssh. If your terminal supports OSC 52 (it probably does), here's a way to get that to work over ssh or mosh: cat - | base64 -w0 | { printf '\e]52;c;' ; cat - ; printf '\a' ; } Put that in a shell script, maybe "remote-copy", and then do: cmd-with-output | remote-copy and it appears in your local clipboard. I had to fiddle a bit with tmux, which by default handles that OSC 52 stuff itself and intercepts it. I did set -g set-clipboard on set -ga terminal-overrides ',foot*:Ms=\E]52;%p1%s;%p2%s\a' in my tmux config - I use the "foot" terminal, you'll have to change that suitably. The script needs base64 because in the printf string, if the input has a semicolon, escape byte, null byte, or similar special things, it will mess up printf. Base64 avoids all that. See https://ghostty.org/docs/vt/osc/52 -- it seems there are some other intriguing OSC commands there. The particular pieces to what's here: \e] says an escape sequence is starting 52 it's sequence 52 ;c; put stuff into the "clipboard" target then there's the payload, and a \a marks the end. #shell #terminal #command_line

Replies (0)

No replies.