natecraddock / sessions.nvim

a simple session manager plugin
MIT License
133 stars 8 forks source link

Fix session save on Windows when absolute = true #2

Closed JManch closed 1 year ago

JManch commented 1 year ago

I was getting the following error when attempting to save sessions with absolute = true on Windows:

E5108: Error executing lua ...te\pack\packer\start\sessions.nvim/lua\sessions\init.lua:68: Vim(mksession):E190: Cannot open "C:\Users\Joshua\AppData\Local\nvim-data\sessions\:.Users.Joshua..config.nvim.session" for writing
stack traceback:
    [C]: in function 'cmd'
    ...te\pack\packer\start\sessions.nvim/lua\sessions\init.lua:68: in function 'write_session_file'
    ...te\pack\packer\start\sessions.nvim/lua\sessions\init.lua:124: in function 'save'
    ...te\pack\packer\start\sessions.nvim/lua\sessions\init.lua:204: in function 'parse_args'
    [string ":lua"]:1: in main chunk

There was an bug in the safe_path function causing paths on Windows to have a leading ":". Fix is to simply remove two characters instead of one if the OS is Windows.

natecraddock commented 1 year ago

Hi! Thank you for this fix, I sometimes forget Windows has C:\ as a prefix. The intended purpose of the :sub(2) was to remove the single / character on unix absolute paths, and I think it might be even better to use a :sub(4) so the entire C:\ is stripped here. That way things are consistent between Windows and Unix-like systems.

Could you make that small update and make sure it works? Then I'll gladly merge this.

JManch commented 1 year ago

Oh yeah, that makes sense. I've tested it on sub(4) and it works fine.

natecraddock commented 1 year ago

Thanks for updating it!