Skip to content

Commit 3460f28

Browse files
akinshokyazdani42
authored andcommitted
Add config option to follow buffer directory
1 parent 5fcbc21 commit 3460f28

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

lua/tree.lua

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,15 @@ function M.check_windows_and_close()
153153
end
154154
end
155155

156+
function M.navigate_to_buffer_dir(bufname)
157+
local new_path = get_cwd()
158+
if new_path ~= '/' then
159+
new_path = new_path .. '/'
160+
end
161+
set_root_path(new_path)
162+
init_tree()
163+
end
164+
156165
function M.check_buffer_and_open()
157166
local bufname = api.nvim_buf_get_name(0)
158167
if bufname == '' then
@@ -169,12 +178,7 @@ function M.check_buffer_and_open()
169178

170179
M.toggle()
171180
else
172-
local new_path = get_cwd()
173-
if new_path ~= '/' then
174-
new_path = new_path .. '/'
175-
end
176-
set_root_path(new_path)
177-
init_tree()
181+
M.navigate_to_buffer_dir()
178182
end
179183
end
180184

plugin/tree.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ augroup LuaTree
1919
au VimEnter * lua require'tree'.check_buffer_and_open()
2020
endif
2121

22+
2223
if get(g:, 'lua_tree_follow') != 0
2324
au BufEnter * :LuaTreeFindFile
2425
endif
2526

27+
au BufEnter * lua require'tree'.navigate_to_buffer_dir()
2628
au ColorScheme * lua require'tree'.reset_highlight()
2729
augroup end
2830

0 commit comments

Comments
 (0)