Skip to content

Commit

Permalink
feat(recipes): improve auto-session-restore by triggering it once
Browse files Browse the repository at this point in the history
Co-authored-by: Micah Halter <micah@mehalter.com>
  • Loading branch information
Kamilcuk and mehalter committed Jun 14, 2024
1 parent 431417e commit d0dc34a
Showing 1 changed file with 19 additions and 27 deletions.
46 changes: 19 additions & 27 deletions lua/astrocommunity/recipes/auto-session-restore/init.lua
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
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,
},
"AstroNvim/astrocore",
---@type AstroCoreOpts
opts = {
autocmds = {
-- disable alpha autostart
alpha_autostart = false,
restore_session = {
{
event = { "VimEnter", "StdinReadPost" },
desc = "Restore previous directory session if neovim opened with no arguments",
once = true, -- delete itself after executing once
nested = true, -- trigger other autocommands as buffers open
callback = function(args)
-- Only load the session if nvim was started with no args
if args.event == "VimEnter" 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,
},
},
},
Expand Down

0 comments on commit d0dc34a

Please sign in to comment.