From ac6d7e8b07c40ff0c175716851feeb43614cd0dc Mon Sep 17 00:00:00 2001 From: voidarc Date: Fri, 27 Feb 2026 16:44:58 +0000 Subject: [PATCH] cleaned up new autocommand --- init.lua | 59 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/init.lua b/init.lua index b829205..837dd47 100644 --- a/init.lua +++ b/init.lua @@ -5,36 +5,6 @@ vim.g.maplocalleader = "," -- Lazy require("config.lazy") -vim.api.nvim_create_autocmd("VimEnter", { - callback = function() - -- Verify if the current directory is a git repo - local is_git = os.execute("git rev-parse --is-inside-work-tree > /dev/null 2>&1") - if is_git ~= 0 then - return - end - - -- Perform an async fetch to avoid startup lag - vim.fn.jobstart("git fetch", { - on_exit = function() - -- Get the number of commits the remote is ahead of local HEAD - local count = vim.fn.system("git rev-list --count HEAD..@{u} 2>/dev/null"):gsub("%s+", "") - - if count ~= "" and tonumber(count) > 0 then - vim.schedule(function() - vim.notify( - "󰊢 " .. count .. " new commit(s) available on remote.", - vim.log.levels.INFO, - { title = "Git Status", icon = "󰊢" } - ) - end) - else - vim.notify("all good") - end - end, - }) - end, -}) - -- Line numbers vim.opt.cursorline = true vim.wo.relativenumber = true @@ -138,3 +108,32 @@ end, { noremap = true }) Keymap("n", "l", function() Snacks.lazygit.open() end) + +-- Autocommand to check git status +vim.api.nvim_create_autocmd("VimEnter", { + callback = function() + -- Verify if the current directory is a git repo + local is_git = os.execute("git rev-parse --is-inside-work-tree > /dev/null 2>&1") + if is_git ~= 0 then + return + end + + -- Perform an async fetch to avoid startup lag + vim.fn.jobstart("git fetch", { + on_exit = function() + -- Get the number of commits the remote is ahead of local HEAD + local count = vim.fn.system("git rev-list --count HEAD..@{u} 2>/dev/null"):gsub("%s+", "") + + if count ~= "" and tonumber(count) > 0 then + vim.schedule(function() + vim.notify( + "󰊢 " .. count .. " new commit(s) available on remote.", + vim.log.levels.INFO, + { title = "Git Status", icon = "󰊢" } + ) + end) + end + end, + }) + end, +})