From 431417e404f368ed4dc3813023a71971b5a51637 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 | 33 +++++++++++++++++++ 2 files changed, 39 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 00000000..613cbcfa --- /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 00000000..a5582fc5 --- /dev/null +++ b/lua/astrocommunity/recipes/auto-session-restore/init.lua @@ -0,0 +1,33 @@ +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, + }, + }, + }, + }, + }, +}