From 8c010498c70cfc87a1d6e7791c837cbd30b07586 Mon Sep 17 00:00:00 2001 From: Prad Nukala Date: Sat, 15 Aug 2026 15:15:22 -0400 Subject: [PATCH] feat(plugins): add git-branch-aware session handling and disable dashboard startup --- lua/plugins/astrocore.lua | 35 +++++++++++++++++++++++--------- lua/plugins/user.lua | 42 +++------------------------------------ 2 files changed, 29 insertions(+), 48 deletions(-) diff --git a/lua/plugins/astrocore.lua b/lua/plugins/astrocore.lua index 97c9d7c..7f4b4c8 100644 --- a/lua/plugins/astrocore.lua +++ b/lua/plugins/astrocore.lua @@ -71,9 +71,11 @@ return { ---@type AstroCoreOpts opts = { sessions = { + -- cwd autosave is handled by the git_branch_sessions autocmd below so + -- the session name carries the worktree/branch, see config.session autosave = { last = true, - cwd = true, + cwd = false, }, ignore = { dirs = {}, @@ -153,18 +155,23 @@ return { end, }, }, - restore_session = { + git_branch_sessions = { + { + event = "VimLeavePre", + desc = "Save the worktree/branch directory session on close", + callback = vim.schedule_wrap(function() + if require("astrocore.buffer").is_valid_session() then + require("config.session").save { notify = false } + end + end), + }, { event = "VimEnter", - desc = "Restore previous directory session if neovim opened with no arguments", + desc = "Restore worktree/branch session, else open the git files picker", nested = true, -- trigger other autocommands as buffers open callback = function() - if vim.fn.argc(-1) == 0 then - require("resession").load( - vim.fn.getcwd(), - { dir = "dirsession", silence_errors = true } - ) - end + -- only when nvim was started without file arguments + if vim.fn.argc(-1) == 0 then require("config.session").restore() end end, }, }, @@ -208,6 +215,16 @@ return { function() require("snacks").picker.git_files { transform = file_filter } end, desc = "Find git files", }, + -- AstroNvim's dirsession maps key off the bare cwd; use the + -- worktree/branch-aware name instead + ["SS"] = { + function() require("config.session").save() end, + desc = "Save this dirsession", + }, + ["S."] = { + function() require("config.session").load() end, + desc = "Load current dirsession", + }, [""] = { function() require("snacks").picker.smart() end, desc = "Find files", diff --git a/lua/plugins/user.lua b/lua/plugins/user.lua index 71bf325..d4b1611 100644 --- a/lua/plugins/user.lua +++ b/lua/plugins/user.lua @@ -53,45 +53,9 @@ return { jump = { reuse_win = true }, sources = picker_sources, }, - dashboard = { - enabled = true, - preset = { - -- "prdlk.nvim" in ansi_regular block style - header = table.concat({ - "██████ ██████ ██████ ██ ██ ██ ███ ██ ██ ██ ██ ███ ███", - "██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ████ ████", - "██████ ██████ ██ ██ ██ █████ ██ ██ ██ ██ ██ ██ ██ ████ ██", - "██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██", - "██ ██ ██ ██████ ███████ ██ ██ ██ ██ ████ ████ ██ ██ ██", - }, "\n"), - }, - sections = { - { section = "header" }, - { section = "keys", gap = 1, padding = 1 }, - { - icon = " ", - desc = "Browse Repo", - padding = 1, - key = "b", - action = function() Snacks.gitbrowse() end, - }, - { - icon = " ", - desc = "Projects (ghq)", - padding = 1, - key = "p", - action = function() - local repos = vim.fn.systemlist "ghq list -p" - vim.ui.select(repos, { prompt = "Select repository" }, function(dir) - if not dir then return end - vim.cmd.cd(dir) - Snacks.picker.files() - end) - end, - }, - { section = "startup" }, - }, - }, + -- no dashboard: startup either restores the worktree/branch session or + -- opens the git files picker (see config.session) + dashboard = { enabled = false }, }, },