From 6f00ebfb347f04f08b87db86c2f541e5a1f3cb27 Mon Sep 17 00:00:00 2001 From: Oscar Wallberg Date: Thu, 31 Oct 2024 19:21:19 +0100 Subject: [PATCH] fix(statusline): handle non-git buffers better --- lua/core/options.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lua/core/options.lua b/lua/core/options.lua index 51ac956..012ec10 100644 --- a/lua/core/options.lua +++ b/lua/core/options.lua @@ -77,21 +77,26 @@ vim.opt.updatetime = 100 function _G._status_line_git() local status = vim.b.gitsigns_status_dict + if not status then return '' end + local added = status.added or 0 + local changed = status.changed or 0 + local removed = status.removed or 0 + local parts = {} - if status.added > 0 then + if added > 0 then table.insert(parts, string.format("%%#GitSignsAdd#+%d%%*", status.added)) end - if status.changed > 0 then + if changed > 0 then table.insert(parts, string.format('%%#GitSignsChange#~%d%%*', status.changed)) end - if status.removed > 0 then + if removed > 0 then table.insert(parts, string.format('%%#GitSignsDelete#-%d%%*', status.removed)) end