-
-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(recipes): add auto-session-restore #1036
Conversation
Review ChecklistDoes this PR follow the [Contribution Guidelines](development guidelines)? Following is a partial checklist: Proper conventional commit scoping:
|
Do you have the link to our documentation? |
Link to docs: https://docs.astronvim.com/recipes/sessions/ |
1f27049
to
431417e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A small suggestion to improve the performance. Thanks so much for opening this up, it's a great addition! Also really like the improvement for the StdinReadPost
d0dc34a
to
431417e
Compare
@Kamilcuk here are 2 options:
return {
"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",
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
return true
end,
},
},
},
},
}
return {
"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",
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
vim.api.nvim_del_augroup_by_name "restore_session"
end,
},
},
},
},
} |
hi:
Both events are printed, so it does not work.
I would be happy with that, but now I have a better version:
I don't like the idea that alpha will not start never. So I copied code from https://github.com/AstroNvim/AstroNvim/blob/365aa6e083dcd25fa3d1c8a2515d7e71a03d51d3/lua/astronvim/plugins/alpha.lua#L44 . If there is a session, use it, otherwise show alpha. This actually works and shows alpha on directories without session, but loads session with directories with session. And also |
Nice! I like this one! I think the only thing is adding protection against if alpha isn't installed |
…when no session available
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thanks so much!
📑 Description
Adds auto-session-restore like in documentation, but also detect if nvim has been started with stdin redirected, like
stream | nvim
or likeexport MAPAGER='nvim +Man!'; man man
.The stdin detection is taken from https://github.com/thaerkh/vim-workspace/blob/master/plugin/workspace.vim#L268 .
ℹ Additional Information
Would be nice to add the stdin input handling also to documentation.