<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>docs/hyperlinks.md - fork/wezterm @ termiz-0.23.3</title>
<meta name="description" content="docs/hyperlinks.md in fork/wezterm at termiz-0.23.3.">
<meta property="og:title" content="docs/hyperlinks.md - fork/wezterm @ termiz-0.23.3">
<meta property="og:description" content="docs/hyperlinks.md in fork/wezterm at termiz-0.23.3.">
<meta property="og:type" content="website">
<meta property="og:site_name" content="git.julia.blue">
<link rel="stylesheet" href="/css/style.css?v=62">
<script type="module" src="/js/main.js?v=62"></script>
</head>
<body>
<main data-ref="termiz-0.23.3" data-tip="4bf28e253c0167102f07bfc7e7199c13eed98012">
<noscript>
  <div class="callout">
    <p>
      hey! this is a static git repo viewer. commit diffs, file history,
      older commits and other revisions won't load without javascript.
    </p>
    <p>
      you are still able to view source files on branch/tag tips,
      but the experience is degraded.
    </p>
  </div>
</noscript>
<header class="repo"><div>
<h1>fork/wezterm</h1>
</div>
<pre class="clone">git clone https://git.julia.blue/fork/wezterm</pre>
</header>
<p class="snapshot-commit"><span class="commit-author">Wez Furlong</span><span class="commit-message" data-commit="11c4b11669d9ce23d51afaf286b5383fbdc9794f">s,wez/wezterm,wezterm/wezterm,</span><span class="snapshot-sha sha" data-commit="11c4b11669d9ce23d51afaf286b5383fbdc9794f">11c4b1166</span><time datetime="2025-02-07T13:08:01-07:00" title="2025-02-07 13:08:01 -0700">2025-02-07</time></p>
<header class="topbar"><details class="switcher"><summary>termiz-0.23.3</summary><div class="menu"><strong>branches</strong><a href="/fork/wezterm/ref/main/">main</a><strong>tags</strong><a href="/fork/wezterm/ref/termiz-0.23.1/">termiz-0.23.1</a><a href="/fork/wezterm/ref/termiz-0.23.2/">termiz-0.23.2</a><a class="current" href="/fork/wezterm/ref/termiz-0.23.3/">termiz-0.23.3</a><a href="/fork/wezterm/ref/termwiz-0.23.0/">termwiz-0.23.0</a><a href="/fork/wezterm/ref/termwiz-0.23.1/">termwiz-0.23.1</a><a href="/fork/wezterm/ref/termwiz-0.23.2/">termwiz-0.23.2</a><a href="/fork/wezterm/ref/termwiz-0.23.3/">termwiz-0.23.3</a><a href="/fork/wezterm/ref/vtparse-0.7.0/">vtparse-0.7.0</a><a class="all" href="/fork/wezterm/refs">all refs →</a></div></details><nav class="crumbs"><a href="/fork/wezterm/">wezterm</a> / <a href="/fork/wezterm/ref/termiz-0.23.3/tree/docs/">docs</a> / <span class="cur">hyperlinks.md</span></nav>
<span class="view-stats"><span>2.2 KiB</span><span>60 lines</span></span><span class="actions"><a class="raw" href="/fork/wezterm/raw/c874c56187be400ec44a2b559d93e17d00632a39/docs/hyperlinks.md">raw</a></span></header>
<div class="markdown-view"><input type="radio" name="markdown-view" id="markdown-rendered" checked><label for="markdown-rendered">rendered</label><input type="radio" name="markdown-view" id="markdown-code"><label for="markdown-code">code</label><section class="readme rendered"><p>wezterm has support for both implicit and explicit hyperlinks.</p>
<h3>Implicit Hyperlinks</h3>
<p>Implicit hyperlinks are produced by running a series of rules over the output
displayed in the terminal to produce a hyperlink.  There is a default rule
to match URLs and make them clickable, but you can also specify your own rules
to make your own links.</p>
<p>As an example, at my place of work many of our internal tools use <code>T123</code> to
indicate task number 123 in our internal task tracking system.  It is desirable
to make this clickable, and that can be done with the following configuration
in your <code>~/.wezterm.lua</code>:</p>
<pre class="language-lua"><a-k>local</a-k> <a-v>wezterm</a-v> = <a-f>require</a-f> <a-s>&#39;wezterm&#39;</a-s>
<a-k>local</a-k> <a-v>config</a-v> = <a-cr>{}</a-cr>

<a-c>-- Use the defaults as a base</a-c>
<a-v>config</a-v><a-p>.</a-p><a-v>hyperlink_rules</a-v> = <a-v>wezterm</a-v><a-p>.</a-p><a-f>default_hyperlink_rules</a-f><a-p>()</a-p>

<a-c>-- make task numbers clickable</a-c>
<a-c>-- the first matched regex group is captured in $1.</a-c>
<a-v>table</a-v><a-p>.</a-p><a-f>insert</a-f><a-p>(</a-p><a-v>config</a-v><a-p>.</a-p><a-v>hyperlink_rules</a-v><a-p>,</a-p> <a-cr>{</a-cr>
  <a-v>regex</a-v> = <a-s>[[\b[tt](\d+)\b]]</a-s><a-p>,</a-p>
  <a-v>format</a-v> = <a-s>&#39;https://example.com/tasks/?t=$1&#39;</a-s><a-p>,</a-p>
<a-cr>}</a-cr><a-p>)</a-p>

<a-c>-- make username/project paths clickable. this implies paths like the following are for github.</a-c>
<a-c>-- ( &quot;nvim-treesitter/nvim-treesitter&quot; | wbthomason/packer.nvim | wezterm/wezterm | &quot;wezterm/wezterm.git&quot; )</a-c>
<a-c>-- as long as a full url hyperlink regex exists above this it should not match a full url to</a-c>
<a-c>-- github or gitlab / bitbucket (i.e. https://gitlab.com/user/project.git is still a whole clickable url)</a-c>
<a-v>table</a-v><a-p>.</a-p><a-f>insert</a-f><a-p>(</a-p><a-v>config</a-v><a-p>.</a-p><a-v>hyperlink_rules</a-v><a-p>,</a-p> <a-cr>{</a-cr>
  <a-v>regex</a-v> = <a-s>[[[&quot;]?([\w\d]{1}[-\w\d]+)(/){1}([-\w\d\.]+)[&quot;]?]]</a-s><a-p>,</a-p>
  <a-v>format</a-v> = <a-s>&#39;https://www.github.com/$1/$3&#39;</a-s><a-p>,</a-p>
<a-cr>}</a-cr><a-p>)</a-p>

<a-k>return</a-k> <a-v>config</a-v></pre>
<p>See also <a href="/fork/wezterm/ref/termiz-0.23.3/blob/docs/config/lua/config/hyperlink_rules.md">hyperlink_rules</a> and
<a href="/fork/wezterm/ref/termiz-0.23.3/blob/docs/config/lua/wezterm/default_hyperlink_rules.md">default_hyperlink_rules</a>.</p>
<h3>Explicit Hyperlinks</h3>
<p>wezterm supports the relatively new <a href="https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda">Hyperlinks in Terminal
Emulators</a>
specification that allows emitting text that can be clicked and resolve to a
specific URL, without the URL being part of the display text.  This allows
for a cleaner presentation.</p>
<p>The gist of it is that running the following bash one-liner:</p>
<pre class="language-bash"><a-f>printf</a-f> <a-s>&#39;\e]8;;http://example.com\e\\This is a link\e]8;;\e\\\n&#39;</a-s></pre>
<p>will output the text <code>This is a link</code> that when clicked will open
<code>http://example.com</code> in your browser.</p>
</section><div class="code-panel"><pre class="code src language-markdown"><span class="code-line"><a class="ln" id="L1" href="#L1">1</a><span class="code-text">wezterm has support for both implicit and explicit hyperlinks.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L2" href="#L2">2</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L3" href="#L3">3</a><span class="code-text"><a-p>###</a-p> <a-tt>Implicit Hyperlinks</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L4" href="#L4">4</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L5" href="#L5">5</a><span class="code-text">Implicit hyperlinks are produced by running a series of rules over the output</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L6" href="#L6">6</a><span class="code-text">displayed in the terminal to produce a hyperlink.  There is a default rule</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L7" href="#L7">7</a><span class="code-text">to match URLs and make them clickable, but you can also specify your own rules</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L8" href="#L8">8</a><span class="code-text">to make your own links.</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L9" href="#L9">9</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L10" href="#L10">10</a><span class="code-text">As an example, at my place of work many of our internal tools use `T123` to</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L11" href="#L11">11</a><span class="code-text">indicate task number 123 in our internal task tracking system.  It is desirable</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L12" href="#L12">12</a><span class="code-text">to make this clickable, and that can be done with the following configuration</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L13" href="#L13">13</a><span class="code-text">in your `~/.wezterm.lua`:</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L14" href="#L14">14</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L15" href="#L15">15</a><span class="code-text"><a-p>```</a-p><a-tl>lua</a-tl></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L16" href="#L16">16</a><span class="code-text"><a-p>local </a-p><a-v>wezterm</a-v><a-p> = </a-p><a-f>require</a-f><a-p> </a-p><a-s>&#39;wezterm&#39;</a-s></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L17" href="#L17">17</a><span class="code-text"><a-p>local </a-p><a-v>config</a-v><a-p> = </a-p><a-cr>{}</a-cr></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L18" href="#L18">18</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L19" href="#L19">19</a><span class="code-text"><a-p>-- Use the defaults as a base</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L20" href="#L20">20</a><span class="code-text"><a-p>config.</a-p><a-v>hyperlink_rules</a-v><a-p> = </a-p><a-v>wezterm</a-v><a-p>.</a-p><a-f>default_hyperlink_rules</a-f><a-p>()</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L21" href="#L21">21</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L22" href="#L22">22</a><span class="code-text"><a-p>-- make task numbers clickable</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L23" href="#L23">23</a><span class="code-text"><a-p>-- the first matched regex group is captured in $1.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L24" href="#L24">24</a><span class="code-text"><a-p>table.</a-p><a-f>insert</a-f><a-p>(</a-p><a-v>config</a-v><a-p>.</a-p><a-v>hyperlink_rules</a-v><a-p>, </a-p><a-cr>{</a-cr></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L25" href="#L25">25</a><span class="code-text"><a-p>  </a-p><a-v>regex</a-v><a-p> = </a-p><a-s>[[\b[tt](\d+)\b]]</a-s><a-p>,</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L26" href="#L26">26</a><span class="code-text"><a-p>  </a-p><a-v>format</a-v><a-p> = </a-p><a-s>&#39;https://example.com/tasks/?t=$1&#39;</a-s><a-p>,</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L27" href="#L27">27</a><span class="code-text"><a-p>})</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L28" href="#L28">28</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L29" href="#L29">29</a><span class="code-text"><a-p>-- make username/project paths clickable. this implies paths like the following are for github.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L30" href="#L30">30</a><span class="code-text"><a-p>-- ( &quot;nvim-treesitter/nvim-treesitter&quot; | wbthomason/packer.nvim | wezterm/wezterm | &quot;wezterm/wezterm.git&quot; )</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L31" href="#L31">31</a><span class="code-text"><a-p>-- as long as a full url hyperlink regex exists above this it should not match a full url to</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L32" href="#L32">32</a><span class="code-text"><a-p>-- github or gitlab / bitbucket (i.e. https://gitlab.com/user/project.git is still a whole clickable url)</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L33" href="#L33">33</a><span class="code-text"><a-p>table.</a-p><a-f>insert</a-f><a-p>(</a-p><a-v>config</a-v><a-p>.</a-p><a-v>hyperlink_rules</a-v><a-p>, </a-p><a-cr>{</a-cr></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L34" href="#L34">34</a><span class="code-text"><a-p>  </a-p><a-v>regex</a-v><a-p> = </a-p><a-s>[[[&quot;]?([\w\d]{1}[-\w\d]+)(/){1}([-\w\d\.]+)[&quot;]?]]</a-s><a-p>,</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L35" href="#L35">35</a><span class="code-text"><a-p>  </a-p><a-v>format</a-v><a-p> = </a-p><a-s>&#39;https://www.github.com/$1/$3&#39;</a-s><a-p>,</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L36" href="#L36">36</a><span class="code-text"><a-p>})</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L37" href="#L37">37</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L38" href="#L38">38</a><span class="code-text"><a-p>return </a-p><a-v>config</a-v></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L39" href="#L39">39</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L40" href="#L40">40</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L41" href="#L41">41</a><span class="code-text"><a-p>See also [hyperlink_rules](config/lua/config/hyperlink_rules.md) and</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L42" href="#L42">42</a><span class="code-text"><a-p>[default_hyperlink_rules](config/lua/wezterm/default_hyperlink_rules.md).</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L43" href="#L43">43</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L44" href="#L44">44</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L45" href="#L45">45</a><span class="code-text"><a-p>### </a-p><a-tt>Explicit Hyperlinks</a-tt></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L46" href="#L46">46</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L47" href="#L47">47</a><span class="code-text"><a-p>wezterm supports the relatively new [Hyperlinks in Terminal</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L48" href="#L48">48</a><span class="code-text"><a-p>Emulators](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda)</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L49" href="#L49">49</a><span class="code-text"><a-p>specification that allows emitting text that can be clicked and resolve to a</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L50" href="#L50">50</a><span class="code-text"><a-p>specific URL, without the URL being part of the display text.  This allows</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L51" href="#L51">51</a><span class="code-text"><a-p>for a cleaner presentation.</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L52" href="#L52">52</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L53" href="#L53">53</a><span class="code-text"><a-p>The gist of it is that running the following bash one-liner:</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L54" href="#L54">54</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L55" href="#L55">55</a><span class="code-text"><a-p>```</a-p><a-tl>bash</a-tl></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L56" href="#L56">56</a><span class="code-text"><a-p>printf </a-p><a-s>&#39;\e]8;;http://example.com\e\\This is a link\e]8;;\e\\\n&#39;</a-s></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L57" href="#L57">57</a><span class="code-text"><a-p>```</a-p></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L58" href="#L58">58</a><span class="code-text"></span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L59" href="#L59">59</a><span class="code-text">will output the text `This is a link` that when clicked will open</span><span class="code-break">
</span></span><span class="code-line"><a class="ln" id="L60" href="#L60">60</a><span class="code-text">`http://example.com` in your browser.</span></span></pre></div></div>
</main>
</body>
</html>
