Skip to content

fix: use fs_realpath to normalize path #978

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

Merged
merged 1 commit into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lua/nvim-tree/explorer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ local Explorer = {}
Explorer.__index = Explorer

function Explorer.new(cwd)
cwd = utils.path_normalize(cwd or uv.cwd())
cwd = uv.fs_realpath(cwd or uv.cwd())
return setmetatable({
cwd = cwd,
nodes = {}
Expand Down
20 changes: 0 additions & 20 deletions lua/nvim-tree/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -208,24 +208,4 @@ function M.file_exists(path)
return error == nil
end

--- @param num number elements to take
--- @param list table elements
--- @return table
function M.take(num, list)
local t = {}
for i, c in ipairs(list) do
if i > num then break end
table.insert(t, c)
end
return t
end

--- @param path string
--- @return string
function M.path_normalize(path)
local components = vim.split(vim.fn.expand(path), path_separator)
local num_dots = #vim.tbl_filter(function(v) return v == ".." end, components)
return M.path_join(M.take(#components - num_dots * 2, components))
end

return M