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/index.html | 24 ++--- docs/index.xml | 53 +++++++++ docs/posts/OSC-52/index.html | 119 +++++++++++++++++++++ docs/posts/auto-currying_rust_functions/index.html | 2 +- docs/posts/bash_harder_with_vim/index.html | 2 +- docs/posts/call_to_ARMs/index.html | 2 +- docs/posts/color_conundrum/index.html | 2 +- docs/posts/font_size_fallacies/index.html | 2 +- docs/posts/index.html | 43 +++++--- docs/posts/introducing_tablespoon/index.html | 2 +- docs/posts/my_setup/index.html | 2 +- docs/posts/pixel_art_in_GIMP/index.html | 2 +- docs/posts/plain_text_journaling/index.html | 2 +- docs/posts/rapid_refactoring_with_vim/index.html | 2 +- docs/posts/static_sites_with_bash/index.html | 2 +- docs/posts/termux_tandem/index.html | 2 +- docs/posts/turing_complete_type_systems/index.html | 2 +- posts/OSC-52.md | 66 ++++++++++++ recover.sh | 2 + 19 files changed, 295 insertions(+), 38 deletions(-) create mode 100644 docs/posts/OSC-52/index.html create mode 100644 posts/OSC-52.md diff --git a/docs/index.html b/docs/index.html index 2d9b619..a834038 100644 --- a/docs/index.html +++ b/docs/index.html @@ -39,15 +39,15 @@
- 01/08 — 2024 + 28/11 — 2024
- - Introducing Tablespoon + + OSC-52 - 4.5 + 1.9 min @@ -56,15 +56,15 @@
- 29/05 — 2024 + 02/08 — 2024
- - Snip Snap + + Introducing Tablespoon - 2.1 + 4.5 min @@ -73,15 +73,15 @@
- 18/06 — 2023 + 29/05 — 2024
- - Plain Text Journaling + + Snip Snap - 8.9 + 2.1 min diff --git a/docs/index.xml b/docs/index.xml index eec76ca..f8b2aeb 100644 --- a/docs/index.xml +++ b/docs/index.xml @@ -12,6 +12,59 @@ en-us Creative Commons BY-NC-SA 4.0 +OSC-52 +<p>I use <code>ssh</code> a lot. Copying text from the remote machine to +the host machine always sucked. But OSC-52 makes that easy.</p> +<p>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.</p> +<p>What this means is some <code>printf</code> magic can send text to +your clipboard. I store this one-liner in a script called +<code>oclip</code>:</p> +<div class="sourceCode" id="cb1"><pre +class="sourceCode bash"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="bu">printf</span> <span class="st">&quot;\033]52;c;%s\007&quot;</span> <span class="st">&quot;</span><span class="va">$(</span><span class="fu">base64</span> <span class="op">&lt;&amp;</span><span class="dv">0</span><span class="va">)</span><span class="st">&quot;</span></span></code></pre></div> +<p>and I run it with:</p> +<div class="sourceCode" id="cb2"><pre +class="sourceCode bash"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="ex">remote</span> $ cat some_file.txt <span class="kw">|</span> <span class="ex">oclip</span></span> +<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a></span> +<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="co"># some_file.txt&#39;s contents are now the host&#39;s clipboard</span></span></code></pre></div> +<h3 id="the-catch">The catch</h3> +<p>Your terminal emulator must support OSC-52, <code>alacritty</code> +and <code>termux</code> seem to support this out of the box. In +<code>st</code>, OSC-52 works with this change to +<code>config.h</code>:</p> +<pre><code>int allowwindowops = 1;</code></pre> +<p>If you are using <code>tmux</code>, you need to flip this switch +on:</p> +<pre><code>set -s set-clipboard on</code></pre> +<p>If you are inside <code>nvim</code>, it may work as expected as long +as <code>$SSH_TTY</code> is set. I sometimes physically start a session, +and <code>ssh</code> into the same session later from another machine, +and <code>$SSH_TTY</code> remains unset, so I force OSC-52 in +<code>nvim</code> at all times (see <a +href="https://neovim.io/doc/user/provider.html#clipboard-osc52">nvimdoc</a>):</p> +<div class="sourceCode" id="cb5"><pre +class="sourceCode lua"><code class="sourceCode lua"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="va">vim</span><span class="op">.</span><span class="va">g</span><span class="op">.</span><span class="va">clipboard</span> <span class="op">=</span> <span class="op">{</span></span> +<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a> <span class="va">name</span> <span class="op">=</span> <span class="st">&#39;OSC 52&#39;</span><span class="op">,</span></span> +<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a> <span class="va">copy</span> <span class="op">=</span> <span class="op">{</span></span> +<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a> <span class="op">[</span><span class="st">&#39;+&#39;</span><span class="op">]</span> <span class="op">=</span> <span class="fu">require</span><span class="op">(</span><span class="st">&#39;vim.ui.clipboard.osc52&#39;</span><span class="op">).</span>copy<span class="op">(</span><span class="st">&#39;+&#39;</span><span class="op">),</span></span> +<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a> <span class="op">[</span><span class="st">&#39;*&#39;</span><span class="op">]</span> <span class="op">=</span> <span class="fu">require</span><span class="op">(</span><span class="st">&#39;vim.ui.clipboard.osc52&#39;</span><span class="op">).</span>copy<span class="op">(</span><span class="st">&#39;*&#39;</span><span class="op">),</span></span> +<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a> <span class="op">},</span></span> +<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a> <span class="va">paste</span> <span class="op">=</span> <span class="op">{</span></span> +<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a> <span class="op">[</span><span class="st">&#39;+&#39;</span><span class="op">]</span> <span class="op">=</span> <span class="fu">require</span><span class="op">(</span><span class="st">&#39;vim.ui.clipboard.osc52&#39;</span><span class="op">).</span>paste<span class="op">(</span><span class="st">&#39;+&#39;</span><span class="op">),</span></span> +<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a> <span class="op">[</span><span class="st">&#39;*&#39;</span><span class="op">]</span> <span class="op">=</span> <span class="fu">require</span><span class="op">(</span><span class="st">&#39;vim.ui.clipboard.osc52&#39;</span><span class="op">).</span>paste<span class="op">(</span><span class="st">&#39;*&#39;</span><span class="op">),</span></span> +<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a> <span class="op">},</span></span> +<span id="cb5-11"><a href="#cb5-11" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div> +<p>If you are inside <code>nvim</code> inside <code>tmux</code> inside +an <code>ssh</code> session inside <code>st</code>, you neeed all of the +above tweaks. <code>nvim</code> will pass the contents around to +<code>tmux</code>, which in turn will pass the contents to +<code>st</code>, which should pass it to your system clipboard.</p> +https://peppe.rs/posts/OSC-52/ +Wed, 27 Nov 2024 22:56:00 +0000 +https://peppe.rs/posts/OSC-52/ + + Introducing Tablespoon <p><a href="https://git.peppe.rs/languages/tbsp">tbsp</a> (tree-based source-processing language) is an awk-like language that operates on 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 +
+
+ + diff --git a/docs/posts/auto-currying_rust_functions/index.html b/docs/posts/auto-currying_rust_functions/index.html index c06b13f..9ea7246 100644 --- a/docs/posts/auto-currying_rust_functions/index.html +++ b/docs/posts/auto-currying_rust_functions/index.html @@ -25,7 +25,7 @@ ">View Raw
- 08/05 — 2020 + 09/05 — 2020
356.44 diff --git a/docs/posts/bash_harder_with_vim/index.html b/docs/posts/bash_harder_with_vim/index.html index 6104163..7d3c869 100644 --- a/docs/posts/bash_harder_with_vim/index.html +++ b/docs/posts/bash_harder_with_vim/index.html @@ -25,7 +25,7 @@ ">View Raw
- 30/07 — 2019 + 31/07 — 2019
24.38 diff --git a/docs/posts/call_to_ARMs/index.html b/docs/posts/call_to_ARMs/index.html index 71b5397..f5b92f7 100644 --- a/docs/posts/call_to_ARMs/index.html +++ b/docs/posts/call_to_ARMs/index.html @@ -25,7 +25,7 @@ ">View Raw
- 07/02 — 2020 + 08/02 — 2020
33.57 diff --git a/docs/posts/color_conundrum/index.html b/docs/posts/color_conundrum/index.html index 87bc495..a98741a 100644 --- a/docs/posts/color_conundrum/index.html +++ b/docs/posts/color_conundrum/index.html @@ -25,7 +25,7 @@ ">View Raw
- 30/12 — 2019 + 31/12 — 2019
14.39 diff --git a/docs/posts/font_size_fallacies/index.html b/docs/posts/font_size_fallacies/index.html index 871a536..5cf8485 100644 --- a/docs/posts/font_size_fallacies/index.html +++ b/docs/posts/font_size_fallacies/index.html @@ -25,7 +25,7 @@ ">View Raw
- 16/03 — 2020 + 17/03 — 2020
32.37 diff --git a/docs/posts/index.html b/docs/posts/index.html index a8d321c..f70098b 100644 --- a/docs/posts/index.html +++ b/docs/posts/index.html @@ -27,7 +27,24 @@
- 01/08 — 2024 + 28/11 — 2024 +
+ + OSC-52 + + + + + 1.9 + + min + + + + + +
+ 02/08 — 2024
Introducing Tablespoon @@ -61,7 +78,7 @@
- 18/06 — 2023 + 19/06 — 2023
Plain Text Journaling @@ -248,7 +265,7 @@
- 17/06 — 2020 + 18/06 — 2020
Turing Complete Type Systems @@ -265,7 +282,7 @@
- 08/05 — 2020 + 09/05 — 2020
Auto-currying Rust Functions @@ -282,7 +299,7 @@
- 08/04 — 2020 + 09/04 — 2020
Pixel Art In GIMP @@ -299,7 +316,7 @@
- 31/03 — 2020 + 01/04 — 2020
Rapid Refactoring With Vim @@ -316,7 +333,7 @@
- 16/03 — 2020 + 17/03 — 2020
Font Size Fallacies @@ -333,7 +350,7 @@
- 07/03 — 2020 + 08/03 — 2020
Termux Tandem @@ -350,7 +367,7 @@
- 07/02 — 2020 + 08/02 — 2020
Call To ARMs @@ -367,7 +384,7 @@
- 30/12 — 2019 + 31/12 — 2019
Color Conundrum @@ -384,7 +401,7 @@
- 22/11 — 2019 + 23/11 — 2019
Static Sites With Bash @@ -401,7 +418,7 @@
- 06/11 — 2019 + 07/11 — 2019
My Setup @@ -469,7 +486,7 @@
- 30/07 — 2019 + 31/07 — 2019
Bash Harder With Vim diff --git a/docs/posts/introducing_tablespoon/index.html b/docs/posts/introducing_tablespoon/index.html index a6f6ef2..c097cfa 100644 --- a/docs/posts/introducing_tablespoon/index.html +++ b/docs/posts/introducing_tablespoon/index.html @@ -25,7 +25,7 @@ ">View Raw
- 01/08 — 2024 + 02/08 — 2024
72.33 diff --git a/docs/posts/my_setup/index.html b/docs/posts/my_setup/index.html index 9844d52..a5cdef5 100644 --- a/docs/posts/my_setup/index.html +++ b/docs/posts/my_setup/index.html @@ -25,7 +25,7 @@ ">View Raw
- 06/11 — 2019 + 07/11 — 2019
10.39 diff --git a/docs/posts/pixel_art_in_GIMP/index.html b/docs/posts/pixel_art_in_GIMP/index.html index 25db0ca..122fd35 100644 --- a/docs/posts/pixel_art_in_GIMP/index.html +++ b/docs/posts/pixel_art_in_GIMP/index.html @@ -25,7 +25,7 @@ ">View Raw
- 08/04 — 2020 + 09/04 — 2020
55.54 diff --git a/docs/posts/plain_text_journaling/index.html b/docs/posts/plain_text_journaling/index.html index b4b4c54..ae47471 100644 --- a/docs/posts/plain_text_journaling/index.html +++ b/docs/posts/plain_text_journaling/index.html @@ -25,7 +25,7 @@ ">View Raw
- 18/06 — 2023 + 19/06 — 2023
138.66 diff --git a/docs/posts/rapid_refactoring_with_vim/index.html b/docs/posts/rapid_refactoring_with_vim/index.html index cd10d02..622243d 100644 --- a/docs/posts/rapid_refactoring_with_vim/index.html +++ b/docs/posts/rapid_refactoring_with_vim/index.html @@ -25,7 +25,7 @@ ">View Raw
- 31/03 — 2020 + 01/04 — 2020
79.12 diff --git a/docs/posts/static_sites_with_bash/index.html b/docs/posts/static_sites_with_bash/index.html index 8e6441a..293fa62 100644 --- a/docs/posts/static_sites_with_bash/index.html +++ b/docs/posts/static_sites_with_bash/index.html @@ -25,7 +25,7 @@ ">View Raw
- 22/11 — 2019 + 23/11 — 2019
21.18 diff --git a/docs/posts/termux_tandem/index.html b/docs/posts/termux_tandem/index.html index 15eb01f..cf7fb77 100644 --- a/docs/posts/termux_tandem/index.html +++ b/docs/posts/termux_tandem/index.html @@ -25,7 +25,7 @@ ">View Raw
- 07/03 — 2020 + 08/03 — 2020
19.18 diff --git a/docs/posts/turing_complete_type_systems/index.html b/docs/posts/turing_complete_type_systems/index.html index 214e7ff..5a87edf 100644 --- a/docs/posts/turing_complete_type_systems/index.html +++ b/docs/posts/turing_complete_type_systems/index.html @@ -25,7 +25,7 @@ ">View Raw
- 17/06 — 2020 + 18/06 — 2020
9.19 diff --git a/posts/OSC-52.md b/posts/OSC-52.md new file mode 100644 index 0000000..8dccef9 --- /dev/null +++ b/posts/OSC-52.md @@ -0,0 +1,66 @@ +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`: + +```bash +printf "\033]52;c;%s\007" "$(base64 <&0)" +``` + +and I run it with: + +```bash +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](https://neovim.io/doc/user/provider.html#clipboard-osc52)): + +```lua +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. diff --git a/recover.sh b/recover.sh index 5c827aa..5ce0171 100755 --- a/recover.sh +++ b/recover.sh @@ -1,3 +1,5 @@ +#! /usr/bin/env nix-shell +#! nix-shell -i bash -p dateutils LIMIT=5000 read_dom () { ORIGINAL_IFS=$IFS -- cgit v1.2.3