refactor(git): split status code parsing into status.lua

This commit is contained in:
2026-04-30 17:24:11 +02:00
parent 9f44c9de40
commit eebe191371
4 changed files with 57 additions and 52 deletions
+52
View File
@@ -0,0 +1,52 @@
local M = {}
M.UNMERGED = {
DD = true,
AU = true,
UD = true,
UA = true,
DU = true,
AA = true,
UU = true,
}
---@param code string
---@return string? char
---@return string? hl_group
function M.indicator(code)
if code == "" then
return nil
end
if code == "??" then
return "?", "GitUntracked"
end
if code == "!!" then
return "!", "GitIgnored"
end
if M.UNMERGED[code] then
return "U", "GitUnmerged"
end
local x, y = code:sub(1, 1), code:sub(2, 2)
if x == "R" or y == "R" then
return "R", "GitRenamed"
end
if y == " " and x ~= " " then
return x, "GitStaged"
end
if y == "D" then
return "D", "GitDeleted"
end
return "M", "GitUnstaged"
end
---@param code string
---@return string?
function M.format(code)
local char, hl = M.indicator(code)
if not char then
return nil
end
return string.format("%%#%s#%s%%*", hl, char)
end
return M