olimorris / persisted.nvim

💾 Simple session management for Neovim with git branching, autoloading and Telescope support
MIT License
418 stars 24 forks source link

fix: unnecessary shell commands when autosave off #85

Closed rafi closed 11 months ago

rafi commented 11 months ago

Problem: Shell programs aren't able to detect nvim exit.

Solution: Avoid running shell-commands unnecessarily on exit. _Tested with opts = { autoload = true, follow_cwd = false }_

Programs that spawn nvim in-order to edit a file are unable to detect nvim exit cleanly because of a race-condition that happens in VimLeavePre and get_current() which runs shell commands during exit even when autosave is off.

To reproduce, use nvim nightly, run persisted.nvim with:

opts.should_autosave = function()
    -- Do not autosave if git commit/rebase session.
    return vim.env.GIT_EXEC_PATH == nil
end

And run EDITOR=nvim git commit from shell; git will fail waiting for nvim to exit cleanly.

olimorris commented 11 months ago

Many thanks. Really nice catch!