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

Cannot open files in home directory in Cygwin #170

Open
delphinus opened this issue Jan 25, 2024 · 2 comments
Open

Cannot open files in home directory in Cygwin #170

delphinus opened this issue Jan 25, 2024 · 2 comments

Comments

@delphinus
Copy link
Member

delphinus commented Jan 25, 2024

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

  1. :cd C:\Windows (outside of the home directory)
  2. :Telescope frecency and try to open C:\Users\foo\AppData\Local\Nvim\init.lua
  3. Internally, it makes the path be normalized: ~\AppData\Local\Nvim\init.lua.
  4. Then Neovim tries to open ~\AppData\Local\Nvim\init.lua, and then fails. This is because ~ is not C:\Users\foo but \home\foo in Cygwin.

procedure to open files successfully

  1. :cd C:\Users\foo (home directory)
  2. :Telescope frecency and try to open C:\Users\foo\AppData\Local\Nvim\init.lua
  3. Internally, it makes the path to relative one: AppData\Local\Nvim\init.lua.
  4. Neovim successfully opens the file.
@delphinus
Copy link
Member Author

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.

@delphinus
Copy link
Member Author

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

1 participant