diff --git a/neovim/.config/nvim/after/plugin/lualine.lua b/neovim/.config/nvim/after/plugin/lualine.lua index a0f5f9f..2c08b23 100644 --- a/neovim/.config/nvim/after/plugin/lualine.lua +++ b/neovim/.config/nvim/after/plugin/lualine.lua @@ -1,6 +1,34 @@ local lualine = require("lualine") 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 = { "mode", } @@ -102,6 +130,12 @@ local tabs = { }, } +local git_status = { + function() + return "勒" .. gstatus.ahead .. " " .. gstatus.behind .. "" + end, +} + lualine.setup({ options = { component_separators = "", @@ -125,7 +159,7 @@ lualine.setup({ sections = { lualine_a = { mode }, lualine_b = { branch }, - lualine_c = { diagnostics }, + lualine_c = { diagnostics, git_status }, lualine_x = { diff, location, tabstop, fileformat }, lualine_y = { filetype }, lualine_z = {},