telescope-frecency.nvim
telescope-frecency.nvim copied to clipboard
Cannot open files in home directory in Cygwin
ref #164
This is because vim.uv.os_homedir() returns C:\Users\foo, but the exact home directory ($HOME) in Cygwin is C:\cygwin64\home\foo.
procedure to fail opening files
:cd C:\Windows(outside of the home directory):Telescope frecencyand try to openC:\Users\foo\AppData\Local\Nvim\init.lua- Internally, it makes the path be normalized:
~\AppData\Local\Nvim\init.lua. - Then Neovim tries to open
~\AppData\Local\Nvim\init.lua, and then fails. This is because~is notC:\Users\foobut\home\fooin Cygwin.
procedure to open files successfully
:cd C:\Users\foo(home directory):Telescope frecencyand try to openC:\Users\foo\AppData\Local\Nvim\init.lua- Internally, it makes the path to relative one:
AppData\Local\Nvim\init.lua. - Neovim successfully opens the file.
This is caused by plenary.nvim's path.lua itself. Path:normalize() makes vim.uv.os_homedir() string into ~, but ~ is not $HOME in Cygwin. With this diff below, it works validly.
diff --git a/lua/plenary/path.lua b/lua/plenary/path.lua
index a253859..64df772 100644
--- a/lua/plenary/path.lua
+++ b/lua/plenary/path.lua
@@ -368,16 +368,18 @@ function Path:normalize(cwd)
self:make_relative(cwd)
- -- Substitute home directory w/ "~"
- -- string.gsub is not useful here because usernames with dashes at the end
- -- will be seen as a regexp pattern rather than a raw string
- local home = path.home
- if string.sub(path.home, -1) ~= path.sep then
- home = home .. path.sep
- end
- local start, finish = string.find(self.filename, home, 1, true)
- if start == 1 then
- self.filename = "~" .. path.sep .. string.sub(self.filename, (finish + 1), -1)
+ if path.home == vim.env.HOME then
+ -- Substitute home directory w/ "~"
+ -- string.gsub is not useful here because usernames with dashes at the end
+ -- will be seen as a regexp pattern rather than a raw string
+ local home = path.home
+ if string.sub(path.home, -1) ~= path.sep then
+ home = home .. path.sep
+ end
+ local start, finish = string.find(self.filename, home, 1, true)
+ if start == 1 then
+ self.filename = "~" .. path.sep .. string.sub(self.filename, (finish + 1), -1)
+ end
end
return _normalize_path(clean(self.filename), self._cwd)
Should we change this? Still considering.
telescope.nvim calls Path:normalize ↓here. This is the problem.
https://github.com/nvim-telescope/telescope.nvim/blob/da8b3d485975a8727bea127518b65c980521ae22/lua/telescope/actions/set.lua#L199-L199