Due to a weird font rendering bug in kitty, I switched to alacritty as my
primary terminal emulator for the time being.
One missing feature when doing Debian and Ubuntu work is the possibility
to click on bug numbers to open them in a web browser. Ubuntu
patches gnome-terminal (60_add_lp_handler.patch) to match LP:
#2076389 strings and allow to click them to open the corresponding Launchpad
bug page.
alacritty does support custom hints with the help of regexes, so we can define
our own to open both Launchpad and Debian BTS bugs:
[[hints.enabled]]
regex = "LP: #[\\d]+"
command = { program = "/home/gagath/.config/alacritty/open-bug.py" }
mouse = { enabled = true }
[[hints.enabled]]
regex = "#[\\d]+"
command = { program = "/home/gagath/.config/alacritty/open-bug.py" }
mouse = { enabled = true }
Note that we need to use the full path, because the interpretation of ~
seems to not be supported at the moment in the version I am using. No big
deal.
The text captured by the regex will be passed to the specified program. This
is why we need some glue code to parse the regex again and to construct the
URL out of it, before replacing the script’s process with xdg-open that
will open the URL.
#!/usr/bin/env python3
import re
import sys
import os
MATCHES = [
(r"LP: #([\d]+)", "https://bugs.launchpad.net/bugs/{}"),
(r"#([\d]+)", "https://bugs.debian.org/cgi-bin/bugreport.cgi?bug={}"),
]
XDG_OPEN = "/usr/bin/xdg-open"
def url_of_text(text):
for (regex, url) in MATCHES:
match = re.match(regex, text)
if match is None:
continue
return url.format(match.group(1))
def main():
text = sys.argv[1]
url = url_of_text(text)
assert url is not None
os.execv(XDG_OPEN, [XDG_OPEN, url])
if __name__ == "__main__":
main()
However, providing custom hints seems to disable the default hint that is
used for finding links. So I had to copy-paste it back at the end of the
configuration file to make the “classic” hints work again.
[[hints.enabled]]
command = "xdg-open"
hyperlinks = true
post_processing = true
persist = false
mouse.enabled = true
binding = { key = "U", mods = "Control|Shift" }
regex = "(ipfs:|ipns:|magnet:|mailto:|gemini://|gopher://|https://|http://|news:|file:|git://|ssh:|ftp://)[^\u0000-\u001F\u007F-\u009F<>\"\\s{-}\\^⟨⟩`]+"
Maybe the Debian and Ubuntu versions of alacritty could be patched to
include this kind of hints by default, but that is left as an exercise for
the reader.