From 92a1fd5c5ee1fb0b4079128a0b7c6a1d78a2399d Mon Sep 17 00:00:00 2001 From: Akshay Date: Thu, 28 Nov 2024 04:31:48 +0530 Subject: new post: OSC-52 --- docs/posts/OSC-52/index.html | 119 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 docs/posts/OSC-52/index.html (limited to 'docs/posts/OSC-52') diff --git a/docs/posts/OSC-52/index.html b/docs/posts/OSC-52/index.html new file mode 100644 index 0000000..6c87fef --- /dev/null +++ b/docs/posts/OSC-52/index.html @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + OSC-52 · peppe.rs + +
+
+ Home + / + Posts + / + OSC-52 + View Raw +
+
+ 28/11 — 2024 +
+ + 26.37 + + cm +   + + 1.9 + + min +
+
+

+ OSC-52 +

+
+

I use ssh a lot. Copying text from the remote machine to +the host machine always sucked. But OSC-52 makes that easy.

+

OSC-52 is an ANSI escape sequence to write text to the terminal +emulator. The terminal emulator, if it understands what is going on, +will in turn write this text to the system clipboard.

+

What this means is some printf magic can send text to +your clipboard. I store this one-liner in a script called +oclip:

+
printf "\033]52;c;%s\007" "$(base64 <&0)"
+

and I run it with:

+
remote $ cat some_file.txt | oclip
+
+# some_file.txt's contents are now the host's clipboard
+

The catch

+

Your terminal emulator must support OSC-52, alacritty +and termux seem to support this out of the box. In +st, OSC-52 works with this change to +config.h:

+
int allowwindowops = 1;
+

If you are using tmux, you need to flip this switch +on:

+
set -s set-clipboard on
+

If you are inside nvim, it may work as expected as long +as $SSH_TTY is set. I sometimes physically start a session, +and ssh into the same session later from another machine, +and $SSH_TTY remains unset, so I force OSC-52 in +nvim at all times (see nvimdoc):

+
vim.g.clipboard = {
+  name = 'OSC 52',
+  copy = {
+    ['+'] = require('vim.ui.clipboard.osc52').copy('+'),
+    ['*'] = require('vim.ui.clipboard.osc52').copy('*'),
+  },
+  paste = {
+    ['+'] = require('vim.ui.clipboard.osc52').paste('+'),
+    ['*'] = require('vim.ui.clipboard.osc52').paste('*'),
+  },
+}
+

If you are inside nvim inside tmux inside +an ssh session inside st, you neeed all of the +above tweaks. nvim will pass the contents around to +tmux, which in turn will pass the contents to +st, which should pass it to your system clipboard.

+ +
+ +
+ Hi. + +

I'm Akshay, programmer and pixel-artist. + I write open-source stuff. + I also design fonts: + scientifica, + curie. +

+

Reach out at oppili@irc.rizon.net.

+
+ + Home + / + Posts + / + OSC-52 + View Raw +
+
+ + -- cgit v1.2.3