Hyperlink escape codes

Mar 14, 2024

To print out a clickable hyperlink in a [terminal that supports] the OSC8 escape code, using bash:

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

Found via trying to get the gh cli to output nicer code search results that I can get more context from

Here's a python function that returns an appropriately escaped hyperlink ready for display in the terminal:

def link(url, link):
    return f'\033]8;;{url}\033\\{link}\033]8;;\033\\'

note that this assumes your URL is properly URL-escaped.

↑ up