neovim(lualine): add git_status component

This commit is contained in:
2022-09-13 22:42:10 +03:00
parent 59f883fd6e
commit 7731e74d65

View File

@@ -1,6 +1,34 @@
local lualine = require("lualine") local lualine = require("lualine")
local devicons = require("nvim-web-devicons") local devicons = require("nvim-web-devicons")
local gstatus = { ahead = 0, behind = 0 }
local function update_gstatus()
local Job = require("plenary.job")
Job:new({
command = "git",
args = { "rev-list", "--left-right", "--count", "HEAD...@{upstream}" },
on_exit = function(job, _)
local res = job:result()[1]
if type(res) ~= "string" then
gstatus = { ahead = 0, behind = 0 }
return
end
local ok, ahead, behind = pcall(string.match, res, "(%d+)%s*(%d+)")
if not ok then
ahead, behind = 0, 0
end
gstatus = { ahead = ahead, behind = behind }
end,
}):start()
end
if _G.Gstatus_timer == nil then
_G.Gstatus_timer = vim.loop.new_timer()
else
_G.Gstatus_timer:stop()
end
_G.Gstatus_timer:start(0, 2000, vim.schedule_wrap(update_gstatus))
local mode = { local mode = {
"mode", "mode",
} }
@@ -102,6 +130,12 @@ local tabs = {
}, },
} }
local git_status = {
function()
return "" .. gstatus.ahead .. "" .. gstatus.behind .. ""
end,
}
lualine.setup({ lualine.setup({
options = { options = {
component_separators = "", component_separators = "",
@@ -125,7 +159,7 @@ lualine.setup({
sections = { sections = {
lualine_a = { mode }, lualine_a = { mode },
lualine_b = { branch }, lualine_b = { branch },
lualine_c = { diagnostics }, lualine_c = { diagnostics, git_status },
lualine_x = { diff, location, tabstop, fileformat }, lualine_x = { diff, location, tabstop, fileformat },
lualine_y = { filetype }, lualine_y = { filetype },
lualine_z = {}, lualine_z = {},