From 6b7b1b34fa6c4851a7b06a9ce4a1a703de7fd0ed Mon Sep 17 00:00:00 2001 From: javiertury Date: Sun, 19 Jun 2022 05:59:35 +0200 Subject: [PATCH] feat: add cwd arg to open_replacing_current_buffer (#1348) --- lua/nvim-tree.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index ce15c2e8..d9531a3f 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -95,18 +95,22 @@ function M.open(cwd) end end -function M.open_replacing_current_buffer() +function M.open_replacing_current_buffer(cwd) if view.is_visible() then return end local buf = api.nvim_get_current_buf() local bufname = api.nvim_buf_get_name(buf) - if bufname == "" or vim.loop.fs_stat(bufname) == nil then - return + + if cwd == "" or cwd == nil then + if bufname ~= "" and vim.loop.fs_stat(bufname) ~= nil then + cwd = vim.fn.fnamemodify(bufname, ":p:h") + else + return + end end - local cwd = vim.fn.fnamemodify(bufname, ":p:h") if not core.get_explorer() or cwd ~= core.get_cwd() then core.init(cwd) end