From 1f27049e1cec393858fa3cef1cc4285976c25533 Mon Sep 17 00:00:00 2001 From: KamilCuk Date: Thu, 13 Jun 2024 10:15:25 +0200 Subject: [PATCH] feat(recipes): add auto-session-restore --- .../recipes/auto-session-restore/README.md | 6 ++++ .../recipes/auto-session-restore/init.lua | 35 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 lua/astrocommunity/recipes/auto-session-restore/README.md create mode 100644 lua/astrocommunity/recipes/auto-session-restore/init.lua diff --git a/lua/astrocommunity/recipes/auto-session-restore/README.md b/lua/astrocommunity/recipes/auto-session-restore/README.md new file mode 100644 index 000000000..613cbcfa9 --- /dev/null +++ b/lua/astrocommunity/recipes/auto-session-restore/README.md @@ -0,0 +1,6 @@ +# AstroLSP - Automatically Restore Previous Session + +**Website:** + +This plugin specification configures AstroLSP to automatically +restore their previous session for a given directory when opening Neovim with no arguments. diff --git a/lua/astrocommunity/recipes/auto-session-restore/init.lua b/lua/astrocommunity/recipes/auto-session-restore/init.lua new file mode 100644 index 000000000..11e5cde41 --- /dev/null +++ b/lua/astrocommunity/recipes/auto-session-restore/init.lua @@ -0,0 +1,35 @@ +local read_from_stdin = false +return { + { + "AstroNvim/astrocore", + ---@type AstroCoreOpts + opts = { + autocmds = { + -- disable alpha autostart + alpha_autostart = false, + restore_session = { + { + event = "StdinReadPost", + desc = "Check if we are reading from stdin", + nested = true, + callback = function() + read_from_stdin = true + end, + }, + { + event = "VimEnter", + desc = "Restore previous directory session if neovim opened with no arguments", + nested = true, -- trigger other autocommands as buffers open + callback = function() + -- Only load the session if nvim was started with no args + if not read_from_stdin and vim.fn.argc(-1) == 0 then + -- try to load a directory session using the current working directory + require("resession").load(vim.fn.getcwd(), { dir = "dirsession", silence_errors = true }) + end + end, + }, + }, + }, + }, + }, +}