From ed9d8dbd5ba65d5955278f5b52dde44cc5645ab7 Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Fri, 22 Dec 2023 11:03:17 -0600 Subject: [PATCH] feat(nvim): make GitLinker support self hosted gitlab links --- dots/.config/nvim/lua/plugins/configs/git.lua | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/dots/.config/nvim/lua/plugins/configs/git.lua b/dots/.config/nvim/lua/plugins/configs/git.lua index a6139cf5..b09be6f2 100644 --- a/dots/.config/nvim/lua/plugins/configs/git.lua +++ b/dots/.config/nvim/lua/plugins/configs/git.lua @@ -83,6 +83,45 @@ return { cmd = { "GitLink" }, - config = true + opts = function() + --- @param s string + --- @param t string + local function string_endswith(s, t) + return string.len(s) >= string.len(t) and string.sub(s, #s - #t + 1) == t + end + + --- @param lk gitlinker.Linker + local gitlab_orion_router = function(type) + return function(lk) + local builder = "https://" + .. lk.host + .. "/" + .. (string_endswith(lk.repo, ".git") and lk.repo:sub(1, #lk.repo - 4) or lk.repo) + .. "/" + .. type + .. "/" + .. lk.rev + .. "/" + .. lk.file + .. "#L" + .. lk.lstart + + if lk.lend > lk.lstart then + builder = builder .. "-" .. lk.lend + end + return builder + end + end + return { + router = { + browse = { + ["^gitlab%.orion%-technologies%.io"] = gitlab_orion_router("blob") + }, + blame = { + ["^gitlab%.orion%-technologies%.io"] = gitlab_orion_router("blame") + } + }, + } + end } }