Skip to content

Commit

Permalink
feat(recipes): add auto-session-restore
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamilcuk committed Jun 13, 2024
1 parent d383aaf commit 1f27049
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lua/astrocommunity/recipes/auto-session-restore/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# AstroLSP - Automatically Restore Previous Session

**Website:** <https://docs.astronvim.com/recipes/sessions/#automatically-restore-previous-session>

This plugin specification configures AstroLSP to automatically
restore their previous session for a given directory when opening Neovim with no arguments.
35 changes: 35 additions & 0 deletions lua/astrocommunity/recipes/auto-session-restore/init.lua
Original file line number Diff line number Diff line change
@@ -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,
},
},
},
},
},
}

0 comments on commit 1f27049

Please sign in to comment.