From bbb78b88455c96328b00821fcc6ffdd824cede57 Mon Sep 17 00:00:00 2001 From: Manolis Stamatogiannakis Date: Sun, 19 Jun 2022 22:01:57 +0200 Subject: [PATCH] Updates to documentation for hyperlinks. - Add regex that captures URLs with IP addresses as hosts. - Removed redundant non-capturing parentheses from the first regex. Mirrored the change to default_hyperlink_rules(). - Switched all but the first example to use literal strings for regex (more readable). --- config/src/config.rs | 2 +- docs/hyperlinks.md | 33 ++++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/config/src/config.rs b/config/src/config.rs index 2412277f5..9c24171e1 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -1213,7 +1213,7 @@ fn default_initial_cols() -> u16 { fn default_hyperlink_rules() -> Vec { vec![ // URL with a protocol - hyperlink::Rule::new(r"\b\w+://(?:[\w.-]+)\.[a-z]{2,15}\S*\b", "$0").unwrap(), + hyperlink::Rule::new(r"\b\w+://[\w.-]+\.[a-z]{2,15}\S*\b", "$0").unwrap(), // implicit mailto link hyperlink::Rule::new(r"\b\w+@[\w-]+(\.[\w-]+)+\b", "mailto:$0").unwrap(), // file:// diff --git a/docs/hyperlinks.md b/docs/hyperlinks.md index 938de790f..2a65ca051 100644 --- a/docs/hyperlinks.md +++ b/docs/hyperlinks.md @@ -15,36 +15,51 @@ configuration in your `~/.wezterm.lua`: ```lua return { hyperlink_rules = { - -- Linkify things that look like URLs - -- This is actually the default if you don't specify any hyperlink_rules + -- 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. { - regex = "\\b\\w+://(?:[\\w.-]+)\\.[a-z]{2,15}\\S*\\b", + regex = "\\b\\w+://[\\w.-]+\\.[a-z]{2,15}\\S*\\b", format = "$0", }, -- linkify email addresses + -- Compiled-in default. Used if you don't specify any hyperlink_rules. { - regex = "\\b\\w+@[\\w-]+(\\.[\\w-]+)+\\b", + regex = [[\b\w+@[\w-]+(\.[\w-]+)+\b]], format = "mailto:$0", }, -- file:// URI + -- Compiled-in default. Used if you don't specify any hyperlink_rules. { - regex = "\\bfile://\\S*\\b", + regex = [[\bfile://\S*\b]], + format = "$0", + }, + + -- 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]], format = "$0", }, -- Make task numbers clickable - --[[ + -- The first matched regex group is captured in $1. { - regex = "\\b[tT](\\d+)\\b" - format = "https://example.com/tasks/?t=$1" + regex = [[\b[tT](\d+)\b]], + format = "https://example.com/tasks/?t=$1", } - ]] } } ``` +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. + + ### Explicit Hyperlinks wezterm supports the relatively new [Hyperlinks in Terminal