aboutsummaryrefslogtreecommitdiff
path: root/docs/posts/OSC-52/index.html
diff options
context:
space:
mode:
authorAkshay <[email protected]>2024-11-27 23:01:48 +0000
committerAkshay <[email protected]>2024-11-27 23:01:48 +0000
commit92a1fd5c5ee1fb0b4079128a0b7c6a1d78a2399d (patch)
tree3d1b106db2ca2824d4afffdc433a084e14675772 /docs/posts/OSC-52/index.html
parent9828c78d95f2195cd8e1db04887072cd5f48005b (diff)
new post: OSC-52
Diffstat (limited to 'docs/posts/OSC-52/index.html')
-rw-r--r--docs/posts/OSC-52/index.html119
1 files changed, 119 insertions, 0 deletions
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 @@
1<!DOCTYPE html>
2<html lang="en">
3 <head>
4 <link rel="stylesheet" href="/style.css">
5 <link rel="stylesheet" href="/syntax.css">
6 <meta charset="UTF-8">
7 <meta name="viewport" content="initial-scale=1">
8 <meta content="#ffffff" name="theme-color">
9 <meta name="HandheldFriendly" content="true">
10 <meta property="og:title" content="OSC-52">
11 <meta property="og:type" content="website">
12 <meta property="og:description" content="a static site {for, by, about} me ">
13 <meta property="og:url" content="https://peppe.rs">
14 <link rel="icon" type="image/x-icon" href="/favicon.png">
15 <title>OSC-52 · peppe.rs</title>
16 <body>
17 <div class="posts">
18 <div class="post">
19 <a href="/" class="post-end-link">Home</a>
20 <span>/</span>
21 <a href="/posts" class="post-end-link">Posts</a>
22 <span>/</span>
23 <a class="post-end-link">OSC-52</a>
24 <a class="stats post-end-link" href="https://git.peppe.rs/web/site/plain/posts/OSC-52.md
25">View Raw</a>
26 <div class="separator"></div>
27 <div class="date">
28 28/11 — 2024
29 <div class="stats">
30 <span class="stats-number">
31 26.37
32 </span>
33 <span class="stats-unit">cm</span>
34 &nbsp
35 <span class="stats-number">
36 1.9
37 </span>
38 <span class="stats-unit">min</span>
39 </div>
40 </div>
41 <h1>
42 OSC-52
43 </h1>
44 <div class="post-text">
45 <p>I use <code>ssh</code> a lot. Copying text from the remote machine to
46the host machine always sucked. But OSC-52 makes that easy.</p>
47<p>OSC-52 is an ANSI escape sequence to write text to the terminal
48emulator. The terminal emulator, if it understands what is going on,
49will in turn write this text to the system clipboard.</p>
50<p>What this means is some <code>printf</code> magic can send text to
51your clipboard. I store this one-liner in a script called
52<code>oclip</code>:</p>
53<div class="sourceCode" id="cb1"><pre
54class="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>
55<p>and I run it with:</p>
56<div class="sourceCode" id="cb2"><pre
57class="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>
58<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a></span>
59<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>
60<h3 id="the-catch">The catch</h3>
61<p>Your terminal emulator must support OSC-52, <code>alacritty</code>
62and <code>termux</code> seem to support this out of the box. In
63<code>st</code>, OSC-52 works with this change to
64<code>config.h</code>:</p>
65<pre><code>int allowwindowops = 1;</code></pre>
66<p>If you are using <code>tmux</code>, you need to flip this switch
67on:</p>
68<pre><code>set -s set-clipboard on</code></pre>
69<p>If you are inside <code>nvim</code>, it may work as expected as long
70as <code>$SSH_TTY</code> is set. I sometimes physically start a session,
71and <code>ssh</code> into the same session later from another machine,
72and <code>$SSH_TTY</code> remains unset, so I force OSC-52 in
73<code>nvim</code> at all times (see <a
74href="https://neovim.io/doc/user/provider.html#clipboard-osc52">nvimdoc</a>):</p>
75<div class="sourceCode" id="cb5"><pre
76class="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>
77<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>
78<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>
79<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>
80<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>
81<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a> <span class="op">},</span></span>
82<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>
83<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>
84<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>
85<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a> <span class="op">},</span></span>
86<span id="cb5-11"><a href="#cb5-11" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
87<p>If you are inside <code>nvim</code> inside <code>tmux</code> inside
88an <code>ssh</code> session inside <code>st</code>, you neeed all of the
89above tweaks. <code>nvim</code> will pass the contents around to
90<code>tmux</code>, which in turn will pass the contents to
91<code>st</code>, which should pass it to your system clipboard.</p>
92
93 </div>
94
95 <div class="intro">
96 Hi.
97 <div class="hot-links">
98 <a href="/index.xml" class="feed-button">Subscribe</a>
99 </div>
100 <p>I'm Akshay, programmer and pixel-artist.
101 I write <a href="https://git.peppe.rs">open-source stuff</a>.
102 I also design fonts:
103 <a href="https://git.peppe.rs/fonts/scientifica/about">scientifica</a>,
104 <a href="https://git.peppe.rs/fonts/curie/about">curie</a>.
105 </p>
106 <p>Reach out at [email protected].</p>
107 </div>
108
109 <a href="/" class="post-end-link">Home</a>
110 <span>/</span>
111 <a href="/posts" class="post-end-link">Posts</a>
112 <span>/</span>
113 <a class="post-end-link">OSC-52</a>
114 <a class="stats post-end-link" href="https://git.peppe.rs/web/site/plain/posts/OSC-52.md
115">View Raw</a>
116 </div>
117 </div>
118 </body>
119</html>