-
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(recipes): add auto-session-restore (#1036)
* feat(recipes): add auto-session-restore * feat(auto-session-restore): fix stdin handling and fallback to alpha when no session available
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
return { | ||
{ | ||
"AstroNvim/astrocore", | ||
---@type AstroCoreOpts | ||
opts = { | ||
autocmds = { | ||
-- disable alpha autostart | ||
alpha_autostart = false, | ||
restore_session = { | ||
{ | ||
event = "VimEnter", | ||
desc = "Restore previous directory session if neovim opened with no arguments", | ||
nested = true, -- trigger other autocommands as buffers open | ||
callback = function() | ||
-- Logic copied from https://github.com/AstroNvim/AstroNvim/blob/365aa6e083dcd25fa3d1c8a2515d7e71a03d51d3/lua/astronvim/plugins/alpha.lua#L49 | ||
local should_skip | ||
local lines = vim.api.nvim_buf_get_lines(0, 0, 2, false) | ||
if | ||
vim.fn.argc() > 0 -- don't start when opening a file | ||
or #lines > 1 -- don't open if current buffer has more than 1 line | ||
or (#lines == 1 and lines[1]:len() > 0) -- don't open the current buffer if it has anything on the first line | ||
or #vim.tbl_filter(function(bufnr) return vim.bo[bufnr].buflisted end, vim.api.nvim_list_bufs()) > 1 -- don't open if any listed buffers | ||
or not vim.o.modifiable -- don't open if not modifiable | ||
then | ||
should_skip = true | ||
else | ||
for _, arg in pairs(vim.v.argv) do | ||
if arg == "-b" or arg == "-c" or vim.startswith(arg, "+") or arg == "-S" then | ||
should_skip = true | ||
break | ||
end | ||
end | ||
end | ||
if should_skip then return end | ||
-- if possible, load session | ||
if not pcall(function() require("resession").load(vim.fn.getcwd(), { dir = "dirsession" }) end) then | ||
-- if session was not loaded, if possible, load alpha | ||
require("lazy").load { plugins = { "alpha-nvim" } } | ||
if pcall(function() require("alpha").start(true) end) then | ||
vim.schedule(function() vim.cmd.doautocmd "FileType" end) | ||
end | ||
end | ||
end, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} |