File: fish_git_prompt.html

package info (click to toggle)
fish 4.2.1-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 35,980 kB
  • sloc: python: 6,972; javascript: 1,407; sh: 1,009; xml: 411; ansic: 230; objc: 78; makefile: 20
file content (341 lines) | stat: -rw-r--r-- 25,216 bytes parent folder | download | duplicates (2)
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
<!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>fish_git_prompt - output git information for use in a prompt &#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="fish_greeting - display a welcome message in interactive shells" href="fish_greeting.html" />
    <link rel="prev" title="fish_delta - compare functions and completions to the default" href="fish_delta.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="../index.html">fish-shell 4.2.1 documentation</a> &#187;
    

          <li class="nav-item nav-item-1"><a href="../commands.html" accesskey="U">Commands</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">fish_git_prompt - output git information for use in a prompt</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="../index.html">Documents</a></h3>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../index.html">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 current"><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="../index.html">Sections</a></h4>
<ul>
<li><a class="reference internal" href="#">fish_git_prompt - output git information for use in a prompt</a><ul>
<li><a class="reference internal" href="#synopsis">Synopsis</a></li>
<li><a class="reference internal" href="#description">Description</a></li>
<li><a class="reference internal" href="#example">Example</a></li>
</ul>
</li>
</ul>

</div>
        </div>
      </div>
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="fish-git-prompt-output-git-information-for-use-in-a-prompt">
<h1>fish_git_prompt - output git information for use in a prompt<a class="headerlink" href="#fish-git-prompt-output-git-information-for-use-in-a-prompt" title="Link to this heading">¶</a></h1>
<section id="synopsis">
<h2>Synopsis<a class="headerlink" href="#synopsis" title="Link to this heading">¶</a></h2>
<div class="highlight-fish-synopsis notranslate"><div class="highlight"><pre><span></span><span class="nf">fish_git_prompt</span><span class="w"> </span><span class="g g-Other">[</span><span class="no">FORMAT</span><span class="g g-Other">]</span>
</pre></div>
</div>
<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">fish_prompt</span>
<span class="w">     </span><span class="nf">printf</span><span class="w"> </span><span class="s1">&#39;%s&#39;</span><span class="w"> </span><span class="o">$PWD</span><span class="w"> </span><span class="o">(</span><span class="nf">fish_git_prompt</span><span class="o">)</span><span class="w"> </span><span class="s1">&#39; $ &#39;</span>
<span class="nf">end</span>
</pre></div>
</div>
</section>
<section id="description">
<h2>Description<a class="headerlink" href="#description" title="Link to this heading">¶</a></h2>
<p>The <code class="docutils literal notranslate"><span class="pre">fish_git_prompt</span></code> function displays information about the current git repository, if any.</p>
<p><a class="reference external" href="https://git-scm.com">Git</a> must be installed.</p>
<p>It is possible to modify the output format by passing an argument. The default value is <code class="docutils literal notranslate"><span class="pre">&quot;</span> <span class="pre">(%s)&quot;</span></code>.</p>
<p>There are numerous customization options, which can be controlled with git options or fish variables. git options, where available, take precedence over the fish variable with the same function. git options can be set on a per-repository or global basis. git options can be set with the <code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">config</span></code> command, while fish variables can be set as usual with the <a class="reference internal" href="set.html"><span class="doc">set</span></a> command.</p>
<p>Boolean options (those which enable or disable something) understand “1”, “yes” or “true” to mean true and every other value to mean false.</p>
<ul>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_show_informative_status</span></code> or the git option <code class="docutils literal notranslate"><span class="pre">bash.showInformativeStatus</span></code> can be set to 1, true or yes to enable the “informative” display, which will show a large amount of information - the number of dirty files, unpushed/unpulled commits, and more.
In large repositories, this can take a lot of time, so you may wish to disable it in these repositories with  <code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">config</span> <span class="pre">--local</span> <span class="pre">bash.showInformativeStatus</span> <span class="pre">false</span></code>. It also changes the characters the prompt uses to less plain ones (<code class="docutils literal notranslate"><span class="pre">✚</span></code> instead of <code class="docutils literal notranslate"><span class="pre">*</span></code> for the dirty state for example) , and if you are only interested in that, set <code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_use_informative_chars</span></code> instead.</p>
<p>Because counting untracked files requires a lot of time, the number of untracked files is only shown if enabled via <code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_showuntrackedfiles</span></code> or the git option <code class="docutils literal notranslate"><span class="pre">bash.showUntrackedFiles</span></code>.</p>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_showdirtystate</span></code> or the git option <code class="docutils literal notranslate"><span class="pre">bash.showDirtyState</span></code> can be set to 1, true or yes to show if the repository is “dirty”, i.e. has uncommitted changes.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_showuntrackedfiles</span></code> or the git option <code class="docutils literal notranslate"><span class="pre">bash.showUntrackedFiles</span></code> can be set to 1, true or yes to show if the repository has untracked files (that aren’t ignored).</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_showupstream</span></code> can be set to a list of values to determine how changes between HEAD and upstream are shown:</p>
<blockquote>
<div><dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">auto</span></code></dt><dd><p>summarize the difference between HEAD and its upstream</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">verbose</span></code></dt><dd><p>show number of commits ahead/behind (+/-) upstream</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">name</span></code></dt><dd><p>if verbose, then also show the upstream abbrev name</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">informative</span></code></dt><dd><p>similar to verbose, but shows nothing when equal - this is the default if informative status is enabled.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">git</span></code></dt><dd><p>always compare HEAD to &#64;{upstream}</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">svn</span></code></dt><dd><p>always compare HEAD to your SVN upstream</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">none</span></code></dt><dd><p>disables (useful with informative status)</p>
</dd>
</dl>
</div></blockquote>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_showstashstate</span></code> can be set to 1, true or yes to display the state of the stash.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_shorten_branch_len</span></code> can be set to the number of characters that the branch name will be shortened to.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_describe_style</span></code> can be set to one of the following styles to describe the current HEAD:</p>
<blockquote>
<div><dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">contains</span></code></dt><dd><p>relative to newer annotated tag, such as <code class="docutils literal notranslate"><span class="pre">(v1.6.3.2~35)</span></code></p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">branch</span></code></dt><dd><p>relative to newer tag or branch, such as <code class="docutils literal notranslate"><span class="pre">(master~4)</span></code></p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">describe</span></code></dt><dd><p>relative to older annotated tag, such as <code class="docutils literal notranslate"><span class="pre">(v1.6.3.1-13-gdd42c2f)</span></code></p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">default</span></code></dt><dd><p>an exactly matching tag (<code class="docutils literal notranslate"><span class="pre">(develop)</span></code>)</p>
</dd>
</dl>
<p>If none of these apply, the commit SHA shortened to 8 characters is used.</p>
</div></blockquote>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_showcolorhints</span></code> can be set to 1, true or yes to enable coloring for the branch name and status symbols.</p></li>
</ul>
<p>A number of variables set characters and color used as indicators. Many of these have a different default if used with informative status enabled, or <code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_use_informative_chars</span></code> set. The usual default is given first, then the informative default (if it is different). If no default for the colors is given, they default to <code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_color</span></code>.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_char_stateseparator</span></code> (’ ‘, <code class="docutils literal notranslate"><span class="pre">|</span></code>) - the character to be used between the state characters</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_color</span></code> (no default)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_color_prefix</span></code> - the color of the <code class="docutils literal notranslate"><span class="pre">(</span></code> prefix</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_color_suffix</span></code> - the color of the <code class="docutils literal notranslate"><span class="pre">)</span></code> suffix</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_color_bare</span></code> - the color to use for a bare repository - one without a working tree</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_color_merging</span></code> - the color when a merge/rebase/revert/bisect or cherry-pick is in progress</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_char_cleanstate</span></code> (✔ in informative mode) - the character to be used when nothing else applies</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_color_cleanstate</span></code> (no default)</p></li>
</ul>
<p>Variables used with <code class="docutils literal notranslate"><span class="pre">showdirtystate</span></code>:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_char_dirtystate</span></code> (<cite>*</cite>, ✚) - the number of “dirty” changes, i.e. unstaged files with changes</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_char_invalidstate</span></code> (#, ✖) - the number of “unmerged” changes, e.g. additional changes to already added files</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_char_stagedstate</span></code> (+, ●) - the number of staged files without additional changes</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_color_dirtystate</span></code> (red with showcolorhints, same as color_flags otherwise)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_color_invalidstate</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_color_stagedstate</span></code> (green with showcolorhints, color_flags otherwise)</p></li>
</ul>
<p>Variables used with <code class="docutils literal notranslate"><span class="pre">showstashstate</span></code>:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_char_stashstate</span></code> (<code class="docutils literal notranslate"><span class="pre">$</span></code>, ⚑)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_color_stashstate</span></code> (same as color_flags)</p></li>
</ul>
<p>Variables used with <code class="docutils literal notranslate"><span class="pre">showuntrackedfiles</span></code>:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_char_untrackedfiles</span></code> (%, …) - the symbol for untracked files</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_color_untrackedfiles</span></code> (same as color_flags)</p></li>
</ul>
<p>Variables used with <code class="docutils literal notranslate"><span class="pre">showupstream</span></code> (also implied by informative status):</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_char_upstream_ahead</span></code> (&gt;, ↑) - the character for the commits this repository is ahead of upstream</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_char_upstream_behind</span></code> (&lt;, ↓) - the character for the commits this repository is behind upstream</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_char_upstream_diverged</span></code> (&lt;&gt;, ↓↑) - the symbol if this repository is both ahead and behind upstream</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_char_upstream_equal</span></code> (=) - the symbol if this repo is equal to upstream</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_char_upstream_prefix</span></code> (‘’)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_color_upstream</span></code></p></li>
</ul>
<p>Colors used with <code class="docutils literal notranslate"><span class="pre">showcolorhints</span></code>:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_color_branch</span></code> (green) - the color of the branch if nothing else applies</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_color_branch_detached</span></code> (red) the color of the branch if it’s detached (e.g. a commit is checked out)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_color_branch_dirty</span></code> (no default) the color of the branch if it’s dirty and not detached</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_color_branch_staged</span></code> (no default) the color of the branch if it just has something staged and is otherwise clean</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_color_flags</span></code> (--bold blue) - the default color for dirty/staged/stashed/untracked state</p></li>
</ul>
<p>Note that all colors can also have a corresponding <code class="docutils literal notranslate"><span class="pre">_done</span></code> color. For example, the contents of <code class="docutils literal notranslate"><span class="pre">$__fish_git_prompt_color_upstream_done</span></code> is printed right _after_ the upstream.</p>
<p>See also <a class="reference internal" href="fish_vcs_prompt.html"><span class="doc">fish_vcs_prompt</span></a>, which will call all supported version control prompt functions, including git, Mercurial and Subversion.</p>
</section>
<section id="example">
<h2>Example<a class="headerlink" href="#example" title="Link to this heading">¶</a></h2>
<p>A simple prompt that displays git info:</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">fish_prompt</span>
<span class="w">    </span><span class="c"># ...</span>
<span class="w">    </span><span class="nf">set</span><span class="w"> </span><span class="no">-g</span><span class="w"> </span><span class="no">__fish_git_prompt_showupstream</span><span class="w"> </span><span class="no">auto</span>
<span class="w">    </span><span class="nf">printf</span><span class="w"> </span><span class="s1">&#39;%s %s$&#39;</span><span class="w"> </span><span class="o">$PWD</span><span class="w"> </span><span class="o">(</span><span class="nf">fish_git_prompt</span><span class="o">)</span>
<span class="nf">end</span>
</pre></div>
</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="../index.html">fish-shell 4.2.1 documentation</a> &#187;
    

          <li class="nav-item nav-item-1"><a href="../commands.html" >Commands</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">fish_git_prompt - output git information for use in a prompt</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>