From aee8fe3b2d6f41dcbc4400b3ddc4897f4d776312 Mon Sep 17 00:00:00 2001 From: Prad Nukala Date: Sat, 15 Aug 2026 15:43:32 -0400 Subject: [PATCH] feat(session): skip session restore on startup with file arguments --- lua/config/session.lua | 8 ++++++-- lua/plugins/astrocore.lua | 6 ++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lua/config/session.lua b/lua/config/session.lua index 0358a84..9db2dd0 100644 --- a/lua/config/session.lua +++ b/lua/config/session.lua @@ -75,9 +75,13 @@ end --- VimEnter entry point: restore this worktree/branch session, or fall back to --- the file picker when none has been saved yet. +--- +--- Exception: when nvim was started with file arguments (`nvim foo.lua`, a +--- directory, or `-`) the requested buffer is what the user asked for, so +--- neither the session nor the picker may take the screen. function M.restore() - local name = M.name() - if M.exists(name) then + if vim.fn.argc(-1) > 0 then return end + if M.exists(M.name()) then M.load { silence_errors = true } else -- defer so the picker opens after startup finished drawing the UI diff --git a/lua/plugins/astrocore.lua b/lua/plugins/astrocore.lua index 7f4b4c8..9580009 100644 --- a/lua/plugins/astrocore.lua +++ b/lua/plugins/astrocore.lua @@ -169,10 +169,8 @@ return { event = "VimEnter", desc = "Restore worktree/branch session, else open the git files picker", nested = true, -- trigger other autocommands as buffers open - callback = function() - -- only when nvim was started without file arguments - if vim.fn.argc(-1) == 0 then require("config.session").restore() end - end, + -- no-op when nvim was started with file arguments, see config.session + callback = function() require("config.session").restore() end, }, }, },