linux-cultist / venv-selector.nvim

Allows selection of python virtual environment from within neovim
MIT License
379 stars 40 forks source link

User nil #63

Closed GeraldIr closed 10 months ago

GeraldIr commented 10 months ago

fix: added case where user is root and vim.fn.getenv("USER") returns vim.NIL

cmetz commented 10 months ago

@GeraldIr maybe you want to check if a "vim.env.HOME" works in your case. then you can fix other situations where the user home folder is not under /home

GeraldIr commented 10 months ago

@cmetz thanks for the suggestion, that definitely simplifies the code and increases the cases that can be covered. I'm unsure how this would behave under windows hence why I didn't touch that part.

linux-cultist commented 10 months ago

Thank you - I didnt notice this was hardcoded before and it shouldnt be of course.

Im using the M.getenv() function in other places in the file to make sure we get an empty string instead of nil if the environment variable doesnt exist. Maybe we should do the same here.

What does vim.env.HOME return if $HOME doesnt exist? I tried running vim.env.HOME2 as a test and it returns nil, so if $HOME is not defined, we get this error:

E5108: Error executing lua [string ":lua"]:1: attempt to concatenate field 'HOME' (a nil value)
stack traceback:
    [string ":lua"]:1: in main chunk

On the other hand, Im not sure how much effort we should put into making sure the plugin works when there is no $HOME defined. Its almost always defined on all systems, and this PR at least removes the hardcoded "/home" string so root can run it also.

I will merge it since its a clear improvement over what was there before. :+1: