Hacker News new | ask | show | jobs
by knazarov 1905 days ago
There's a better way to do it. Terminals have a special escape sequence called OSC 52, which allows you to insert into the clipboard from even remote SSH sessions. Try this:

printf "\033]52;c;$(printf "%s" "blabla" | base64)\a"

2 comments

Hey, that's quite interesting. Just tested it here with alacritty and was able to get data from a remote server into the clipboard. The downside here is that it did not seem to work immediately from inside tmux, but a quick search shows that there are ways to make it work. Also found a vim-plugin[1] that would allow it to work from inside vim as well. If I can also find a way to pipe random commands to it, it might indeed work better than clipper for my use cases. Finally, there is the added benefit of removing the need to forward the local UNIX socket over SSH, which I find to be a bit flaky. Thanks for sharing it!

[1] https://github.com/ojroques/vim-oscyank

I've found a couple of random blog posts and some user's pages laying out the OSC codes, but is there an open reference of them?

I have also considered trawling through the various terminal emulator source repos in order to know which are actually implemented (since that can for sure be a different set from those which are specified)