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 14, 2024
1 parent d383aaf commit 431417e
Show file tree
Hide file tree
Showing 2 changed files with 39 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.
33 changes: 33 additions & 0 deletions lua/astrocommunity/recipes/auto-session-restore/init.lua
Original file line number Diff line number Diff line change
@@ -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,
},
},
},
},
},
}

0 comments on commit 431417e

Please sign in to comment.