Skip to content

Commit ab258d9

Browse files
authored
Merge pull request #13 from Akin909/bugfix/follow-buffer-directory
Add config option to follow buffer's directory
2 parents 5fcbc21 + 9201d12 commit ab258d9

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ augroup LuaTree
2323
au BufEnter * :LuaTreeFindFile
2424
endif
2525

26+
au BufEnter * lua require'tree'.navigate_to_buffer_dir()
2627
au ColorScheme * lua require'tree'.reset_highlight()
2728
augroup end
2829

0 commit comments

Comments
 (0)