2020-01-30 04:41:10 +03:00
|
|
|
wezterm has support for both implicit and explicit hyperlinks.
|
|
|
|
|
|
|
|
### Implicit 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
|
2020-04-07 02:32:16 +03:00
|
|
|
configuration in your `~/.wezterm.lua`:
|
|
|
|
|
|
|
|
```lua
|
|
|
|
return {
|
|
|
|
hyperlink_rules = {
|
2022-06-19 23:01:57 +03:00
|
|
|
-- Linkify things that look like URLs and the host has a TLD name.
|
|
|
|
-- Compiled-in default. Used if you don't specify any hyperlink_rules.
|
2020-04-07 02:32:16 +03:00
|
|
|
{
|
2022-07-19 17:54:31 +03:00
|
|
|
regex = '\\b\\w+://[\\w.-]+\\.[a-z]{2,15}\\S*\\b',
|
|
|
|
format = '$0',
|
2020-04-07 02:32:16 +03:00
|
|
|
},
|
|
|
|
|
2021-03-09 18:40:52 +03:00
|
|
|
-- linkify email addresses
|
2022-06-19 23:01:57 +03:00
|
|
|
-- Compiled-in default. Used if you don't specify any hyperlink_rules.
|
2020-04-07 02:32:16 +03:00
|
|
|
{
|
2022-06-19 23:01:57 +03:00
|
|
|
regex = [[\b\w+@[\w-]+(\.[\w-]+)+\b]],
|
2022-07-19 17:54:31 +03:00
|
|
|
format = 'mailto:$0',
|
2020-04-07 02:32:16 +03:00
|
|
|
},
|
2021-03-09 18:40:52 +03:00
|
|
|
|
|
|
|
-- file:// URI
|
2022-06-19 23:01:57 +03:00
|
|
|
-- Compiled-in default. Used if you don't specify any hyperlink_rules.
|
2021-03-09 18:40:52 +03:00
|
|
|
{
|
2022-06-19 23:01:57 +03:00
|
|
|
regex = [[\bfile://\S*\b]],
|
2022-07-19 17:54:31 +03:00
|
|
|
format = '$0',
|
2022-06-19 23:01:57 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
-- Linkify things that look like URLs with numeric addresses as hosts.
|
|
|
|
-- E.g. http://127.0.0.1:8000 for a local development server,
|
|
|
|
-- or http://192.168.1.1 for the web interface of many routers.
|
|
|
|
{
|
|
|
|
regex = [[\b\w+://(?:[\d]{1,3}\.){3}[\d]{1,3}\S*\b]],
|
2022-07-19 17:54:31 +03:00
|
|
|
format = '$0',
|
2021-03-09 18:40:52 +03:00
|
|
|
},
|
2020-04-07 02:32:16 +03:00
|
|
|
|
|
|
|
-- Make task numbers clickable
|
2022-06-19 23:01:57 +03:00
|
|
|
-- The first matched regex group is captured in $1.
|
2020-04-07 02:32:16 +03:00
|
|
|
{
|
2022-06-19 23:01:57 +03:00
|
|
|
regex = [[\b[tT](\d+)\b]],
|
2022-07-19 17:54:31 +03:00
|
|
|
format = 'https://example.com/tasks/?t=$1',
|
2022-06-22 01:15:22 +03:00
|
|
|
},
|
2022-07-19 17:54:31 +03:00
|
|
|
|
2022-06-22 01:50:43 +03:00
|
|
|
-- Make username/project paths clickable. This implies paths like the following are for GitHub.
|
|
|
|
-- ( "nvim-treesitter/nvim-treesitter" | wbthomason/packer.nvim | wez/wezterm | "wez/wezterm.git" )
|
2022-07-19 17:54:31 +03:00
|
|
|
-- As long as a full URL hyperlink regex exists above this it should not match a full URL to
|
2022-06-22 01:50:43 +03:00
|
|
|
-- GitHub or GitLab / BitBucket (i.e. https://gitlab.com/user/project.git is still a whole clickable URL)
|
2022-06-22 01:15:22 +03:00
|
|
|
{
|
|
|
|
regex = [[["]?([\w\d]{1}[-\w\d]+)(/){1}([-\w\d\.]+)["]?]],
|
2022-07-19 17:54:31 +03:00
|
|
|
format = 'https://www.github.com/$1/$3',
|
|
|
|
},
|
|
|
|
},
|
2020-04-07 02:32:16 +03:00
|
|
|
}
|
2020-01-30 04:41:10 +03:00
|
|
|
```
|
|
|
|
|
2022-06-19 23:01:57 +03:00
|
|
|
Note that it is generally convenient to use literal strings (`[[...]]`)
|
|
|
|
when declaring your hyperlink rules, so you won't have to escape
|
|
|
|
backslashes. In the example above, all cases except the first use
|
|
|
|
literal strings for their regular expressions.
|
|
|
|
|
|
|
|
|
2020-01-30 04:41:10 +03:00
|
|
|
### Explicit Hyperlinks
|
|
|
|
|
|
|
|
wezterm supports the relatively new [Hyperlinks in Terminal
|
|
|
|
Emulators](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda)
|
|
|
|
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:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
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.
|