From 212289fa0a3771a620da631200b8704f79748482 Mon Sep 17 00:00:00 2001 From: Eric Hansen Date: Fri, 2 Jul 2021 19:14:41 -0400 Subject: [PATCH 1/4] Update populate.lua If `vim_tree_load_git_file_relatively~= nil` and inside of a Git folder then work out how to load the file via relative path instead of absolute. Otherwise if either condition is nil then fallback to old behavior of absolute path loading. --- lua/nvim-tree/populate.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lua/nvim-tree/populate.lua b/lua/nvim-tree/populate.lua index a2a000e31e0..39592e07a16 100644 --- a/lua/nvim-tree/populate.lua +++ b/lua/nvim-tree/populate.lua @@ -42,6 +42,13 @@ end local function file_new(cwd, name) local absolute_path = utils.path_join({cwd, name}) local is_exec = luv.fs_access(absolute_path, 'X') + local git_root = git.git_root(cwd) + local filename_to_open = absolute_path + + if vim.g.vim_tree_load_git_file_relatively ~= nil and git_root ~= nil then + filename_to_open = utils.path_relative(absolute_path, git_root) + end + return { name = name, absolute_path = absolute_path, @@ -49,6 +56,7 @@ local function file_new(cwd, name) extension = string.match(name, ".?[^.]+%.(.*)") or "", match_name = path_to_matching_str(name), match_path = path_to_matching_str(absolute_path), + filename_to_open = filename_to_open } end From 712bca121c8489afe45a8e4c6546fd1127c758da Mon Sep 17 00:00:00 2001 From: Eric Hansen Date: Fri, 2 Jul 2021 19:16:11 -0400 Subject: [PATCH 2/4] Update nvim-tree.lua --- lua/nvim-tree.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 7a810f17700..1a8f6a568ba 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -80,7 +80,7 @@ local keypress_funcs = { close = function() M.close() end, preview = function(node) if node.entries ~= nil or node.name == '..' then return end - return lib.open_file('preview', node.absolute_path) + return lib.open_file('preview', node.filename_to_open) end, } @@ -106,7 +106,7 @@ function M.on_keypress(mode) elseif node.entries ~= nil then lib.unroll_dir(node) else - lib.open_file(mode, node.absolute_path) + lib.open_file(mode, node.filename_to_open) end end From 107de68313e6872e903ab7e8658be5175af1fdeb Mon Sep 17 00:00:00 2001 From: Eric Hansen Date: Fri, 2 Jul 2021 19:21:26 -0400 Subject: [PATCH 3/4] Update populate.lua --- lua/nvim-tree/populate.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/nvim-tree/populate.lua b/lua/nvim-tree/populate.lua index 39592e07a16..36e10b10e08 100644 --- a/lua/nvim-tree/populate.lua +++ b/lua/nvim-tree/populate.lua @@ -45,7 +45,7 @@ local function file_new(cwd, name) local git_root = git.git_root(cwd) local filename_to_open = absolute_path - if vim.g.vim_tree_load_git_file_relatively ~= nil and git_root ~= nil then + if vim.g.nvim_tree_load_git_file_relatively ~= nil and git_root ~= nil then filename_to_open = utils.path_relative(absolute_path, git_root) end From 50d7f23d115c4d7061fde09a2b90fdf9a1254651 Mon Sep 17 00:00:00 2001 From: Eric Hansen Date: Sat, 3 Jul 2021 07:10:33 -0400 Subject: [PATCH 4/4] Update populate.lua --- lua/nvim-tree/populate.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lua/nvim-tree/populate.lua b/lua/nvim-tree/populate.lua index 36e10b10e08..616e3604da7 100644 --- a/lua/nvim-tree/populate.lua +++ b/lua/nvim-tree/populate.lua @@ -42,11 +42,17 @@ end local function file_new(cwd, name) local absolute_path = utils.path_join({cwd, name}) local is_exec = luv.fs_access(absolute_path, 'X') - local git_root = git.git_root(cwd) local filename_to_open = absolute_path - if vim.g.nvim_tree_load_git_file_relatively ~= nil and git_root ~= nil then - filename_to_open = utils.path_relative(absolute_path, git_root) + local root = function(d) + local git_root = git.git_root(d) + local cwd = luv.cwd() + + if git_root ~= nil then return git_root else return cwd end + end + + if vim.g.nvim_tree_load_git_file_relatively ~= nil then + filename_to_open = utils.path_relative(absolute_path, root(absolute_path)) end return {