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.xml | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'docs/index.xml') 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 -- cgit v1.2.3