From eaaf1ad3a44a641fdac9136bdf86278f48772a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= Date: Tue, 11 Jul 2023 10:26:56 +0200 Subject: [PATCH] url-mode: support for custom prefix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow for the protocol configuration to be: prefix:some_string The url-mode then matches anything starting with this 'some_prefix' prefix. This, combined with a custom launch command able to handle these "URL" allow for opening application specific references (e.g. gitlab short references). Signed-off-by: Marc Poulhiès --- config.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/config.c b/config.c index 3d02355f..cfc95163 100644 --- a/config.c +++ b/config.c @@ -1159,11 +1159,24 @@ parse_section_url(struct context *ctx) conf->url.prot_count * sizeof(conf->url.protocols[0])); size_t idx = conf->url.prot_count - 1; - conf->url.protocols[idx] = xmalloc((chars + 1 + 3) * sizeof(char32_t)); - mbsntoc32(conf->url.protocols[idx], prot, len, chars + 1); - c32cpy(&conf->url.protocols[idx][chars], U"://"); + bool is_custom_prefix = str_has_prefix(prot, "prefix:"); + size_t prot_suffix_len = 3; // the '://' + if (is_custom_prefix) { + prot += 7; + len -= 7; + chars -= 7; + prot_suffix_len = 0; + } + + conf->url.protocols[idx] = xmalloc((chars + 1 + prot_suffix_len) * sizeof(char32_t)); + mbsntoc32(conf->url.protocols[idx], prot, len, chars + 1); + if (!is_custom_prefix) { + c32cpy(&conf->url.protocols[idx][chars], U"://"); + } else { + c32cpy(&conf->url.protocols[idx][chars], U""); + } + chars += prot_suffix_len; - chars += 3; /* Include the "://" */ if (chars > conf->url.max_prot_len) conf->url.max_prot_len = chars; }