Skip to content

Use relative path when possible #486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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

Expand Down
14 changes: 14 additions & 0 deletions lua/nvim-tree/populate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,27 @@ 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 filename_to_open = absolute_path

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 {
name = name,
absolute_path = absolute_path,
executable = is_exec,
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

Expand Down