nvim: statusline: Switch to using git module from mini

This commit is contained in:
Sanchayan Maity 2024-12-09 20:21:06 +05:30
parent e0535da903
commit 0c275b10d0
Signed by: sanchayanmaity
GPG key ID: 6F6A0609C12038F3

View file

@ -1,28 +1,7 @@
local fn = vim.fn
local api = vim.api
local lsp_status = ""
local gstatus = { ahead = 0, behind = 0 }
local lsp_status = ""
local update_status = function()
local Job = require 'plenary.job'
Job:new({
command = 'git',
args = { 'rev-list', '--left-right', '--count', 'HEAD...@{upstream}' },
on_exit = function(exit_job, _)
local res = exit_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()
if vim.lsp.status then
lsp_status = vim.lsp.status()
end
@ -132,16 +111,37 @@ M.get_git_branch = function(self)
return ""
end
return string.format(" %s %s", "%#GitBranch#", fn.FugitiveHead())
local s = vim.b.minigit_summary
if s == nil then
return ""
end
return string.format(" %s %s", "%#GitBranch#", s.head_name)
end
M.get_git_status = function(self)
local is_git = fn.FugitiveHead() ~= ""
local signs = vim.b.minidiff_summary or { add = 0, change = 0, delete = 0 }
local s = vim.b.minigit_summary
if s == nil then
return ""
end
return is_git
and string.format(
" %s+%s %s~%s %s-%s",
local status = ''
if s.head_name then
status = string.format("%s%s", status, s.head_name)
end
if s.status then
status = string.format("%s%s", status, s.status)
end
if s.in_progress then
status = string.format("%s%s", status, s.in_progress)
end
local signs = vim.b.minidiff_summary or { add = 0, change = 0, delete = 0 }
return string.format(
"%s %s+%s %s~%s %s-%s",
"%#GitStatus#",
status,
"%#DiffAdded#",
signs.add or 0,
"%#DiffChanged#",
@ -149,7 +149,6 @@ M.get_git_status = function(self)
"%#DiffRemoved#",
signs.delete or 0
)
or ""
end
M.get_filename = function()
@ -202,16 +201,6 @@ M.progress = function()
return string.format(" %s%s", "%#Progress#", "%3p%% ")
end
M.git_ahead_behind_status = function()
local is_git = fn.FugitiveHead() ~= ""
return
is_git
and
string.format(" %s%s%d%s%d", '%#GitStatus#', '', gstatus.behind, '', gstatus.ahead)
or ""
end
M.get_lsp_status = function(self)
local trunc_width = self.trunc_width.lsp_status
if self:is_truncated(trunc_width) then
@ -229,7 +218,6 @@ M.set_active = function(self)
return table.concat {
self:get_filename(),
self:get_git_status(),
self:git_ahead_behind_status(),
"%=",
self:get_lsp_status(),
self:diagnostic_status(),