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

Wrong path is used in Windows when %HOMEDRIVE% points to other drive #380

Open
guntern opened this issue Apr 11, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@guntern
Copy link

guntern commented Apr 11, 2024

Description

This issue is related to windows. I am currently running Windows 11 23H2.

In our company the environment variables %HOMEDRIVE% and %HOMEPATH% do not point to C:\Users\username, but to a network share. This only happens if the notebook is started within the company. If it is started without connection to the company network those variables point to the "normal" location C:\Users\username.

If I now open neovim inside a directory within C:\Users\username, I can use the file browser and also telescope in general to navigate around in files within this directory or below. This is as expected.

However, if I use the filebrowser plugin to navigate up one level and search for files there (e.g. for reference), it tries to open the file with a full path. But the beginning of said path is not C:\Users\username anymore, but whatever is provided by %HOMEDRIVE%%HOMEPATH%. But the file does not exist there and an empty buffer is opened.

Why is this happening? And how could I solve it within neovim?

I made a test and manually set the two environment variables in the terminal prior to opening neovim. In this situation it is working as expected. But I would prefer to have a neovim solution instead of messing around with the environment variables, which could have unintended side effects.

Neovim version

NVIM v0.9.5
Build type: RelWithDebInfo
LuaJIT 2.1.1703942320

Operating system and version

Windows 11 23H2

Steps to reproduce

  1. Have %HOMEDRIVE% and %HOMEPATH% not point to C:\Users\username
  2. open neovim inside a directory within C:\Users\username, e.g. C:\Users\username\Documents\projectA
  3. use the file explorer plugin and try to open a file outside of this directory, e.g. C:\Users\username\Documents\projectB\README.md

Expected behavior

The file should be opened

Actual behavior

The file is tried to be loaded from %HOMEDRIVE%%HOMEPATH\Documents\projectB\README.md, which does not exist.

Minimal config

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  {
    "nvim-telescope/telescope-file-browser.nvim",
    dependencies = {
      "nvim-telescope/telescope.nvim",
      "nvim-lua/plenary.nvim",
    },
    config = function()
      require("telescope").setup({})
      require("telescope").load_extension("file_browser")
    end,
  },
}

require("lazy").setup(plugins, {
  root = root .. "/plugins",
})
@guntern guntern added the bug Something isn't working label Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant