Skip to content
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

Auto-create session path #37

Open
jblyberg opened this issue Feb 14, 2024 · 3 comments
Open

Auto-create session path #37

jblyberg opened this issue Feb 14, 2024 · 3 comments

Comments

@jblyberg
Copy link

Great plugin--just what I needed.

I have a request that it automatically creates the session path if it doesn't exists. I periodically clear out my .local/share/nvim folder and I'd rather not have to manually recreate the session folder. I know I can store it somewhere else, but it would be nice to keep it all together in the same directory tree.

@gennaro-tedesco
Copy link
Owner

gennaro-tedesco commented Feb 14, 2024

Good evening and thank you for the suggestion!

This could be easily implemented. A little note of historical relevance: when I initially started developing and using the plugin for myself only, I did in fact defaulted the behaviour to automatically create a directory/file path if the current specified location is empty. However, when I decided to expose it to a larger audience, I came to the conclusion that such behaviour might be a little risky and may open the flood gates for all possible misuses (accidental or malicious): a third party plugin should not create a path on the users' computer - creating paths may require/circumvent users' permissions and be possible only for root users on certain machines and so forth; I decided that at most we create a session file provided the user already has the path, i. e. provided the user already consented to create the path on their own machine by doing so themselves (a vim session file contains little to nothing that can be maliciously injected, hence that is fine to create).

As I said, I am somehow "technically" open to the idea but I am not convinced this is the right direction for the scope of a plugin. Let us keep the issue open in case other users chip in, if the vast majority are fine and do not really care about creating/deleting paths automatically I am more than happy to re-default back to auto-creation if the path does not exist :)

@jblyberg
Copy link
Author

Thanks for the thoughtful response. I understand where you're coming from. There might be some ways to address your concern though, like providing a configuration option that users can set to indicate that they would like the config path to be auto-created. The benefit of doing it that way would be that it would have to be done explicitly with the implicit understanding that the plugin would touch the filesystem.

@dapetcu21
Copy link

dapetcu21 commented Mar 24, 2024

I added this to my lazy config and it seems to work:

    build = function()
      local sessions_path = vim.fn.stdpath("data") .. "/sessions"
      if vim.fn.isdirectory(sessions_path) == 0 then
        vim.uv.fs_mkdir(sessions_path, 511) -- 0777
      end
    end,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants