olimorris / persisted.nvim

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

fix: properly resolve directories #105

Closed neandrake closed 6 months ago

neandrake commented 6 months ago

The vim.loop.fs_realpath() function can be used to properly resolve both the . shortcut as well as relative paths. This corrects scenarios when opening nvim to a subdirectory of the working directory. With this change doing so will properly resolve the session file to the directory that was specified on the command line.

$ pwd
/Users/username/.config

$ ls
fish    iterm2    nvim

$ nvim nvim

This will result in using the path /Users/username/.config/nvim for the session. The behavior will be the same as running plain nvim from within the /Users/username/.config/nvim directory itself.

This change also quotes the path passed to git to properly handle paths containing spaces.

This change also corrects some typos in the readme.

olimorris commented 6 months ago

This doesn't work for me. When I have autoload = true and try nvim . I don't get a session autoloading. If I do nvim on its own, I do.

neandrake commented 6 months ago

Could you share more of your persisted configuration? I double-checked that I have this change applied and the test cases I've confirmed are:

$ nvim
$ nvim .
$ nvim subdir

For each testing without existing session file, opening new buffers, closing then restoring. I haven't fully tested on Windows but I did confirm the vim.loop.fs_realpath() returns the same results expected here -- . resolves to current path, subdir expands to absolute path and nonexistant returns nil.

I've also re-tested both git repo folders and non-git repo folders, both of which behave as expected.

Update: I patched these changes on a Windows system and verified the same behaviors.

olimorris commented 6 months ago

Damn! Turned out oil.nvim was intercepting the autoload.

Thanks for the PR!