File: index.html

package info (click to toggle)
fish 4.2.1-3.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,976 kB
  • sloc: python: 6,972; javascript: 1,407; sh: 1,009; xml: 411; ansic: 230; objc: 78; makefile: 20
file content (367 lines) | stat: -rw-r--r-- 25,581 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<!DOCTYPE html>

<html lang="en" data-content_root="./">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />

    <title>Introduction &#8212; fish-shell 4.2.1 documentation</title>
    <link rel="stylesheet" type="text/css" href="_static/pygments.css?v=4da8bbd6" />
    <link rel="stylesheet" type="text/css" href="_static/pydoctheme.css?v=f89b4716" />
    <script src="_static/documentation_options.js?v=6fb65176"></script>
    <script src="_static/doctools.js?v=9bcbadda"></script>
    <script src="_static/sphinx_highlight.js?v=dc90522c"></script>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="Frequently asked questions" href="faq.html" />
    <link rel="shortcut icon" type="image/png" href="_static/fish.png" />
     

  </head><body><div id="fmain">  
    <div class="related" role="navigation" aria-label="Related">
      <h3>Navigation</h3>
      <ul>
    <li><img src="_static/fish.png" alt=""
             style="width: 80px; height: 80px; vertical-align: middle; margin-top: -1px"/></li>
    <li><a href="https://fishshell.com/">fish-shell</a> &#187;</li>
    
    <a href="#">fish-shell 4.2.1 documentation</a> &#187;
    

        <li class="nav-item nav-item-this"><a href="">Introduction</a></li>
    <li class="right">
        

    <div class="inline-search" role="search">
        <form class="inline-search" action="search.html" method="get">
          <input placeholder="Quick search" type="text" name="q" />
          <input type="submit" value="Go" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    </li>
    
    <div id="old-docs-notice" style="display: none">
        This documents an old version of fish.
        <a href="../current/">See the latest release.</a>
    </div>

      </ul>
    </div>    

    <div class="document">
      <div class="sphinxsidebar" role="navigation" aria-label="Main">
        <div class="sphinxsidebarwrapper">
<div>
<h3><a href="#">Documents</a></h3>
<ul class="current">
<li class="toctree-l1 current"><a class="current reference internal" href="#">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="faq.html">Frequently asked questions</a></li>
<li class="toctree-l1"><a class="reference internal" href="interactive.html">Interactive use</a></li>
<li class="toctree-l1"><a class="reference internal" href="language.html">The fish language</a></li>
<li class="toctree-l1"><a class="reference internal" href="commands.html">Commands</a></li>
<li class="toctree-l1"><a class="reference internal" href="fish_for_bash_users.html">Fish for bash users</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorial.html">Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="completions.html">Writing your own completions</a></li>
<li class="toctree-l1"><a class="reference internal" href="prompt.html">Writing your own prompt</a></li>
<li class="toctree-l1"><a class="reference internal" href="design.html">Design</a></li>
<li class="toctree-l1"><a class="reference internal" href="relnotes.html">Release notes</a></li>
<li class="toctree-l1"><a class="reference internal" href="terminal-compatibility.html">Terminal Compatibility</a></li>
<li class="toctree-l1"><a class="reference internal" href="contributing.html">Contributing To Fish</a></li>
<li class="toctree-l1"><a class="reference internal" href="license.html">License</a></li>
</ul>

</div>
<search id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script>
<div>
<h4><a href="#">Sections</a></h4>
<ul>
<li><a class="reference internal" href="#">Introduction</a><ul>
<li><a class="reference internal" href="#where-to-go">Where to go?</a></li>
<li><a class="reference internal" href="#setup">Setup</a><ul>
<li><a class="reference internal" href="#installation">Installation</a></li>
<li><a class="reference internal" href="#starting-and-exiting">Starting and Exiting</a></li>
<li><a class="reference internal" href="#default-shell">Default Shell</a></li>
<li><a class="reference internal" href="#uninstalling">Uninstalling</a></li>
<li><a class="reference internal" href="#shebang-line">Shebang Line</a></li>
</ul>
</li>
<li><a class="reference internal" href="#configuration">Configuration</a><ul>
<li><a class="reference internal" href="#examples">Examples:</a></li>
</ul>
</li>
<li><a class="reference internal" href="#resources">Resources</a></li>
<li><a class="reference internal" href="#other-help-pages">Other help pages</a></li>
</ul>
</li>
</ul>

</div>
        </div>
      </div>
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="introduction">
<span id="intro"></span><h1>Introduction<a class="headerlink" href="#introduction" title="Link to this heading">¶</a></h1>
<p>This is the documentation for <strong class="command">fish</strong>, the <strong>f</strong>riendly <strong>i</strong>nteractive <strong>sh</strong>ell.</p>
<p>A shell is a program that helps you operate your computer by starting other programs. fish offers a command-line interface focused on usability and interactive use.</p>
<p>Some of the special features of fish are:</p>
<ul class="simple">
<li><p><strong>Extensive UI</strong>: <a class="reference internal" href="interactive.html#syntax-highlighting"><span class="std std-ref">Syntax highlighting</span></a>, <a class="reference internal" href="interactive.html#autosuggestions"><span class="std std-ref">Autosuggestions</span></a>, <a class="reference internal" href="interactive.html#tab-completion"><span class="std std-ref">tab completion</span></a> and selection lists that can be navigated and filtered.</p></li>
<li><p><strong>No configuration needed</strong>: fish is designed to be ready to use immediately, without requiring extensive configuration.</p></li>
<li><p><strong>Easy scripting</strong>: New <a class="reference internal" href="language.html#syntax-function"><span class="std std-ref">functions</span></a> can be added on the fly. The syntax is easy to learn and use.</p></li>
</ul>
<p>This page explains how to install and set up fish and where to get more information.</p>
<section id="where-to-go">
<h2>Where to go?<a class="headerlink" href="#where-to-go" title="Link to this heading">¶</a></h2>
<p>If this is your first time using fish, see the <a class="reference internal" href="tutorial.html"><span class="doc">tutorial</span></a>.</p>
<p>If you are already familiar with other shells like bash and want to see the scripting differences, see <a class="reference internal" href="fish_for_bash_users.html"><span class="doc">Fish For Bash Users</span></a>.</p>
<p>For an overview of fish’s scripting language, see <a class="reference internal" href="language.html"><span class="doc">The Fish Language</span></a>. If it would be useful in a script file, it’s here.</p>
<p>For information on using fish interactively, see <a class="reference internal" href="interactive.html"><span class="doc">Interactive use</span></a>. If it’s about key presses, syntax highlighting or anything else that needs an interactive terminal session, look here.</p>
<p>If you need to install fish first, read on, the rest of this document will tell you how to get, install and configure fish.</p>
</section>
<section id="setup">
<h2>Setup<a class="headerlink" href="#setup" title="Link to this heading">¶</a></h2>
<p>This section describes how to install, uninstall, start, and exit <strong class="command">fish</strong>. It also explains how to make fish the default shell.</p>
<section id="installation">
<h3>Installation<a class="headerlink" href="#installation" title="Link to this heading">¶</a></h3>
<p>Up-to-date instructions for installing the latest version of fish are on the <a class="reference external" href="https://fishshell.com/">fish homepage</a>.</p>
<p>To install the development version of fish, see the instructions on the <a class="reference external" href="https://github.com/fish-shell/fish-shell">project’s GitHub page</a>.</p>
</section>
<section id="starting-and-exiting">
<h3>Starting and Exiting<a class="headerlink" href="#starting-and-exiting" title="Link to this heading">¶</a></h3>
<p>Once fish has been installed, open a terminal. If fish is not the default shell:</p>
<ul>
<li><p>Type <strong class="command">fish</strong> to start a shell:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">fish</span>
</pre></div>
</div>
</li>
<li><p>Type <strong class="command">exit</strong> to end the session:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">exit</span>
</pre></div>
</div>
</li>
</ul>
</section>
<section id="default-shell">
<h3>Default Shell<a class="headerlink" href="#default-shell" title="Link to this heading">¶</a></h3>
<p>There are multiple ways to switch to fish (or any other shell) as your default.</p>
<p>The simplest method is to set your terminal emulator (e.g. GNOME Terminal, Apple’s Terminal.app, or Konsole) to start fish directly. See its configuration and set the program to start to <code class="docutils literal notranslate"><span class="pre">/usr/local/bin/fish</span></code> (the exact path depends on how you installed fish).</p>
<p>Alternatively, you can set fish as your login shell so that it will be started by all terminal logins, including SSH.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>Setting fish as your login shell may cause issues, such as an incorrect <span class="target" id="index-0"></span><a class="reference internal" href="language.html#envvar-PATH"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code></a>. Some operating systems, including a number of Linux distributions, require the login shell to be Bourne-compatible and to read configuration from <code class="docutils literal notranslate"><span class="pre">/etc/profile</span></code>. fish may not be suitable as a login shell on these systems.</p>
</div>
<p>To change your login shell to fish:</p>
<ol class="arabic">
<li><p>Add the shell to <code class="docutils literal notranslate"><span class="pre">/etc/shells</span></code> with:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">command</span><span class="w"> </span><span class="no">-v</span><span class="w"> </span><span class="no">fish</span><span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="nf">sudo</span><span class="w"> </span><span class="no">tee</span><span class="w"> </span><span class="no">-a</span><span class="w"> </span><span class="no">/etc/shells</span>
</pre></div>
</div>
</li>
<li><p>Change your default shell with:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt; </span><span class="nf">chsh</span><span class="w"> </span><span class="no">-s</span><span class="w"> </span><span class="s2">&quot;</span><span class="o">$(</span><span class="nf">command</span><span class="w"> </span><span class="no">-v</span><span class="w"> </span><span class="no">fish</span><span class="o">)</span><span class="s2">&quot;</span>
</pre></div>
</div>
</li>
</ol>
<p>To change it back to another shell, substitute <code class="docutils literal notranslate"><span class="pre">fish</span></code> with <code class="docutils literal notranslate"><span class="pre">bash</span></code>, <code class="docutils literal notranslate"><span class="pre">tcsh</span></code> or <code class="docutils literal notranslate"><span class="pre">zsh</span></code> as appropriate in the above command.</p>
</section>
<section id="uninstalling">
<h3>Uninstalling<a class="headerlink" href="#uninstalling" title="Link to this heading">¶</a></h3>
<p>For uninstalling fish: see <a class="reference internal" href="faq.html#faq-uninstalling"><span class="std std-ref">FAQ: Uninstalling fish</span></a>.</p>
</section>
<section id="shebang-line">
<h3>Shebang Line<a class="headerlink" href="#shebang-line" title="Link to this heading">¶</a></h3>
<p>Because shell scripts are written in many different languages, they need to carry information about which interpreter should be used to execute them. For this, they are expected to have a first line, the shebang line, which names the interpreter executable.</p>
<p>A script written in <strong class="command">bash</strong> would need a first line like this:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="c">#!/bin/bash</span>
</pre></div>
</div>
<p>When the shell tells the kernel to execute the file, it will use the interpreter <code class="docutils literal notranslate"><span class="pre">/bin/bash</span></code>.</p>
<p>For a script written in another language, just replace <code class="docutils literal notranslate"><span class="pre">/bin/bash</span></code> with the interpreter for that language. For example: <code class="docutils literal notranslate"><span class="pre">/usr/bin/python</span></code> for a python script, or <code class="docutils literal notranslate"><span class="pre">/usr/local/bin/fish</span></code> for a fish script, if that is where you have them installed.</p>
<p>If you want to share your script with others, you might want to use <strong class="command">env</strong> to allow for the interpreter to be installed in other locations. For example:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="c">#!/usr/bin/env fish</span>
<span class="nf">echo</span><span class="w"> </span><span class="no">Hello</span><span class="w"> </span><span class="no">from</span><span class="w"> </span><span class="no">fish</span><span class="w"> </span><span class="o">$version</span>
</pre></div>
</div>
<p>This will call <code class="docutils literal notranslate"><span class="pre">env</span></code>, which then goes through <span class="target" id="index-1"></span><a class="reference internal" href="language.html#envvar-PATH"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code></a> to find a program called “fish”. This makes it work, whether fish is installed in (for example) <code class="docutils literal notranslate"><span class="pre">/usr/local/bin/fish</span></code>, <code class="docutils literal notranslate"><span class="pre">/usr/bin/fish</span></code>, or <code class="docutils literal notranslate"><span class="pre">~/.local/bin/fish</span></code>, as long as that directory is in <span class="target" id="index-2"></span><a class="reference internal" href="language.html#envvar-PATH"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code></a>.</p>
<p>The shebang line is only used when scripts are executed without specifying the interpreter. For functions inside fish or when executing a script with <code class="docutils literal notranslate"><span class="pre">fish</span> <span class="pre">/path/to/script</span></code>, a shebang is not required (but it doesn’t hurt!).</p>
<p>When executing files without an interpreter, fish, like other shells, tries your system shell, typically <code class="docutils literal notranslate"><span class="pre">/bin/sh</span></code>. This is needed because some scripts are shipped without a shebang line.</p>
</section>
</section>
<section id="configuration">
<h2>Configuration<a class="headerlink" href="#configuration" title="Link to this heading">¶</a></h2>
<p>To store configuration write it to a file called <code class="docutils literal notranslate"><span class="pre">~/.config/fish/config.fish</span></code>.</p>
<p><code class="docutils literal notranslate"><span class="pre">.fish</span></code> scripts in <code class="docutils literal notranslate"><span class="pre">~/.config/fish/conf.d/</span></code> are also automatically executed before <code class="docutils literal notranslate"><span class="pre">config.fish</span></code>.</p>
<p>These files are read on the startup of every shell, whether interactive and/or if they’re login shells. Use <code class="docutils literal notranslate"><span class="pre">status</span> <span class="pre">--is-interactive</span></code> and <code class="docutils literal notranslate"><span class="pre">status</span> <span class="pre">--is-login</span></code> to do things only in interactive/login shells, respectively.</p>
<p>This is the short version; for a full explanation, like for sysadmins or integration for developers of other software, see <a class="reference internal" href="language.html#configuration"><span class="std std-ref">Configuration files</span></a>.</p>
<p>If you want to see what you changed over fish’s defaults, see <a class="reference internal" href="cmds/fish_delta.html"><span class="doc">fish_delta</span></a>.</p>
<section id="examples">
<h3>Examples:<a class="headerlink" href="#examples" title="Link to this heading">¶</a></h3>
<p>To add <code class="docutils literal notranslate"><span class="pre">~/linux/bin</span></code> to PATH variable when using a login shell, add this to <code class="docutils literal notranslate"><span class="pre">~/.config/fish/config.fish</span></code> file:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="nf">if</span><span class="w"> </span><span class="nf">status</span><span class="w"> </span><span class="no">--is-login</span>
<span class="w">    </span><span class="nf">set</span><span class="w"> </span><span class="no">-gx</span><span class="w"> </span><span class="no">PATH</span><span class="w"> </span><span class="o">$PATH</span><span class="w"> </span><span class="o">~</span><span class="no">/linux/bin</span>
<span class="nf">end</span>
</pre></div>
</div>
<p>This is just an example; using <a class="reference internal" href="cmds/fish_add_path.html"><span class="doc">fish_add_path</span></a> e.g. <code class="docutils literal notranslate"><span class="pre">fish_add_path</span> <span class="pre">~/linux/bin</span></code> which only adds the path if it isn’t included yet is easier.</p>
<p>To run commands on exit, use an <a class="reference internal" href="language.html#event"><span class="std std-ref">event handler</span></a> that is triggered by the exit of the shell:</p>
<div class="highlight-fish-docs-samples notranslate"><div class="highlight"><pre><span></span><span class="nf">function</span><span class="w"> </span><span class="no">on_exit</span><span class="w"> </span><span class="no">--on-event</span><span class="w"> </span><span class="no">fish_exit</span>
<span class="w">    </span><span class="nf">echo</span><span class="w"> </span><span class="no">fish</span><span class="w"> </span><span class="no">is</span><span class="w"> </span><span class="no">now</span><span class="w"> </span><span class="no">exiting</span>
<span class="nf">end</span>
</pre></div>
</div>
</section>
</section>
<section id="resources">
<span id="more-help"></span><h2>Resources<a class="headerlink" href="#resources" title="Link to this heading">¶</a></h2>
<ul class="simple">
<li><p>The <a class="reference external" href="https://github.com/fish-shell/fish-shell/">GitHub page</a></p></li>
<li><p>The official <a class="reference external" href="https://matrix.to/#/#fish-shell:matrix.org">Matrix room</a></p></li>
<li><p>The official mailing list at <a class="reference external" href="https://lists.sourceforge.net/lists/listinfo/fish-users">fish-users&#64;lists.sourceforge.net</a></p></li>
</ul>
<p>If you have an improvement for fish, you can submit it via the GitHub page.</p>
</section>
<section id="other-help-pages">
<h2>Other help pages<a class="headerlink" href="#other-help-pages" title="Link to this heading">¶</a></h2>
<div class="toctree-wrapper compound">
<ul class="current">
<li class="toctree-l1 current"><a class="current reference internal" href="#">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="faq.html">Frequently asked questions</a></li>
<li class="toctree-l1"><a class="reference internal" href="interactive.html">Interactive use</a></li>
<li class="toctree-l1"><a class="reference internal" href="language.html">The fish language</a></li>
<li class="toctree-l1"><a class="reference internal" href="commands.html">Commands</a></li>
<li class="toctree-l1"><a class="reference internal" href="fish_for_bash_users.html">Fish for bash users</a></li>
<li class="toctree-l1"><a class="reference internal" href="tutorial.html">Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="completions.html">Writing your own completions</a></li>
<li class="toctree-l1"><a class="reference internal" href="prompt.html">Writing your own prompt</a></li>
<li class="toctree-l1"><a class="reference internal" href="design.html">Design</a></li>
<li class="toctree-l1"><a class="reference internal" href="relnotes.html">Release notes</a></li>
<li class="toctree-l1"><a class="reference internal" href="terminal-compatibility.html">Terminal Compatibility</a></li>
<li class="toctree-l1"><a class="reference internal" href="contributing.html">Contributing To Fish</a></li>
<li class="toctree-l1"><a class="reference internal" href="license.html">License</a></li>
</ul>
</div>
</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div> 
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="Related">
      <h3>Navigation</h3>
      <ul>
    <li><img src="_static/fish.png" alt=""
             style="width: 80px; height: 80px; vertical-align: middle; margin-top: -1px"/></li>
    <li><a href="https://fishshell.com/">fish-shell</a> &#187;</li>
    
    <a href="#">fish-shell 4.2.1 documentation</a> &#187;
    

        <li class="nav-item nav-item-this"><a href="">Introduction</a></li>
    <li class="right">
        

    <div class="inline-search" role="search">
        <form class="inline-search" action="search.html" method="get">
          <input placeholder="Quick search" type="text" name="q" />
          <input type="submit" value="Go" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    </li>
    
    <div id="old-docs-notice" style="display: none">
        This documents an old version of fish.
        <a href="../current/">See the latest release.</a>
    </div>

      </ul>
    </div>  
    <div class="footer">
    &copy; Copyright fish-shell developers.
    <br />
    <a href="https://github.com/fish-shell/fish-shell/issues">Found a bug</a>?
    <br />

    Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.
    </div>
</div>

<script type="text/javascript">
 FISH_DOCS_VERSION = "4.2";

 function copy_to_clipboard(it) {
     // Find the pre tag we're interested in.
     var pre = it.target;
     while (pre.tagName != "PRE") pre = pre.parentNode;
     var txt = "";
     // Cheesy: If we have a prompt,
     // we only copy prompted lines,
     // by splitting and matching and stuff
     if (pre.querySelector('span.gp')) {
         var texts= [];
         for (var line of pre.innerText.split('\n')) {
             if (line.match(/^>_?.*/)) {
                 texts.push(line.replace(/^>_?/, ""));
             }
         }
         txt = texts.join("\n");
     } else {
         // Even cheesier: If we don't have a prompt, we remove the button text from the end.
         var txt = pre.innerText.substring(0, pre.innerText.length - it.target.innerText.length).trim();
     }

     navigator.clipboard.writeText(txt).then(function() {
         // Success - set the text to indicate it,
         // then set it back after 2 seconds.
         var span = pre.querySelector("button span");
         if (span) {
             var oldText = span.innerText;
             span.innerText = "COPIED!";
             setTimeout(function() {
                 span.innerText = oldText;
             }, 2000);
         }
     }, function() {
     });
 }

  (function () {
      // Add copy buttons to all the codeblocks.
      var codeblocks = document.querySelectorAll('div > pre');

      var button = document.createElement('button');
      var span = document.createElement('span');
      span.innerText = "COPY";
      button.appendChild(span);

      for (var i of codeblocks) {
          var newButton = button.cloneNode(true);
          newButton.addEventListener('click', copy_to_clipboard);
          i.appendChild(newButton);
      }
  })();
</script>

  </body>
</html>