File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ local uv = vim.loop
2
2
3
3
local git = require " nvim-tree.git"
4
4
local renderer = require " nvim-tree.renderer"
5
+ local utils = require " nvim-tree.utils"
5
6
6
7
local M = {}
7
8
@@ -12,7 +13,7 @@ local Explorer = {}
12
13
Explorer .__index = Explorer
13
14
14
15
function Explorer .new (cwd )
15
- cwd = cwd or uv .cwd ()
16
+ cwd = utils . path_normalize ( cwd or uv .cwd () )
16
17
return setmetatable ({
17
18
cwd = cwd ,
18
19
nodes = {}
Original file line number Diff line number Diff line change @@ -208,4 +208,24 @@ function M.file_exists(path)
208
208
return error == nil
209
209
end
210
210
211
+ --- @param num number elements to take
212
+ --- @param list table elements
213
+ --- @return table
214
+ function M .take (num , list )
215
+ local t = {}
216
+ for i , c in ipairs (list ) do
217
+ if i > num then break end
218
+ table.insert (t , c )
219
+ end
220
+ return t
221
+ end
222
+
223
+ --- @param path string
224
+ --- @return string
225
+ function M .path_normalize (path )
226
+ local components = vim .split (vim .fn .expand (path ), path_separator )
227
+ local num_dots = # vim .tbl_filter (function (v ) return v == " .." end , components )
228
+ return M .path_join (M .take (# components - num_dots * 2 , components ))
229
+ end
230
+
211
231
return M
You can’t perform that action at this time.
0 commit comments