feat(git): :Glog command, per-module setup, plugin/ auto-init

This commit is contained in:
2026-04-30 15:05:47 +02:00
parent 282ec2602d
commit 217390cfa4
9 changed files with 153 additions and 108 deletions
+50
View File
@@ -84,6 +84,11 @@ end
---@class ow.Git.LogOpts
---@field max_count integer?
---@type table<string, fun(s: string): any>
M.opt_parsers = {
max_count = tonumber,
}
---@param opts ow.Git.LogOpts?
function M.open(opts)
opts = opts or {}
@@ -110,4 +115,49 @@ function M.open(opts)
end
end
function M.setup()
local group = vim.api.nvim_create_augroup("ow.git.log", { clear = true })
vim.api.nvim_create_autocmd("BufReadCmd", {
pattern = "gitlog://*",
group = group,
callback = function(args)
M.read_uri(args.buf)
end,
})
vim.api.nvim_create_user_command("Glog", function(cmd_opts)
local parsed = { max_count = 1000 }
for _, a in ipairs(cmd_opts.fargs) do
local k, v = a:match("^([%w_]+)=(.*)$")
if not k then
util.error("invalid argument: %s", a)
return
end
---@cast v -nil
local parser = M.opt_parsers[k]
if parser then
local value = parser(v)
if value ~= nil then
parsed[k] = value
end
end
end
M.open(parsed)
end, {
nargs = "*",
complete = function(arg_lead)
local matches = {}
for k in pairs(M.opt_parsers) do
local prefix = k .. "="
if prefix:sub(1, #arg_lead) == arg_lead then
table.insert(matches, prefix)
end
end
table.sort(matches)
return matches
end,
desc = "Show git log",
})
end
return M