feat(nvim): make GitLinker support self hosted gitlab links

This commit is contained in:
Price Hiller 2023-12-22 11:03:17 -06:00
parent 2a908db0a5
commit ed9d8dbd5b
Signed by: Price
SSH Key Fingerprint: SHA256:Y4S9ZzYphRn1W1kbJerJFO6GGsfu9O70VaBSxJO7dF8

View File

@ -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
}
}