1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-23 23:21:08 +03:00
wezterm/docs/hyperlinks.md
Sandro d179da3e87 docs/hyperlinks: revert s -> S
Co-authored-by: Wez Furlong <wez@wezfurlong.org>
2021-04-02 21:05:47 -07:00

1.8 KiB

wezterm has support for both implicit and explicit hyperlinks.

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. As an example, at my place of work many of our internal tools use T123 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 ~/.wezterm.lua:

return {
  hyperlink_rules = {
    -- Linkify things that look like URLs
    -- This is actually the default if you don't specify any hyperlink_rules
    {
      regex = "\\b\\w+://(?:[\\w.-]+)\\.[a-z]{2,15}\\S*\\b",
      format = "$0",
    },

    -- linkify email addresses
    {
      regex = "\\b\\w+@[\\w-]+(\\.[\\w-]+)+\\b",
      format = "mailto:$0",
    },

    -- file:// URI
    {
      regex = "\\bfile://\\S*\\b",
      format = "$0",
    },

    -- Make task numbers clickable
    --[[
    {
      regex = "\\b[tT](\\d+)\\b"
      format = "https://example.com/tasks/?t=$1"
    }
    ]]
  }
}

wezterm supports the relatively new Hyperlinks in Terminal Emulators 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.

The gist of it is that running the following bash one-liner:

printf '\e]8;;http://example.com\e\\This is a link\e]8;;\e\\\n'

will output the text This is a link that when clicked will open http://example.com in your browser.