Files
nvim/lua/git/status.lua
T

58 lines
1.1 KiB
Lua

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 string
function M.statusline()
return vim.b.git_status or ""
end
return M