telescope-file-browser.nvim
telescope-file-browser.nvim copied to clipboard
Wrong path is used in Windows when %HOMEDRIVE% points to other drive
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
- Have
%HOMEDRIVE%
and%HOMEPATH%
not point toC:\Users\username
- open neovim inside a directory within
C:\Users\username
, e.g.C:\Users\username\Documents\projectA
- 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",
})