Skip to content

Commit fd3969e

Browse files
authored
feat: add hide_root_folder (#728)
1 parent 6cadd3a commit fd3969e

File tree

6 files changed

+18
-4
lines changed

6 files changed

+18
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ require'nvim-tree'.setup {
9494
width = 30,
9595
-- height of the window, can be either a number (columns) or a string in `%`, for top or bottom side placement
9696
height = 30,
97+
-- Hide the root path of the current folder on top of the tree
98+
hide_root_folder = false,
9799
-- side of the tree, can be one of 'left' | 'right' | 'top' | 'bottom'
98100
side = 'left',
99101
-- if true the tree will resize itself after opening a file

doc/nvim-tree-lua.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ Here is a list of the options available in the setup call:
230230
*nvim-tree.view*
231231
- |view|: window / buffer setup
232232

233+
- |view.hide_root_folder|: hide the path of the current working
234+
directory on top of the tree
235+
type: `boolean`
236+
default: `false`
237+
233238
- |view.width|: width of the window, can be either a `%` string or
234239
a number representing columns. Only works with |view.side| `left` or `right`
235240
type: `string | number`

lua/nvim-tree.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ local DEFAULT_OPTS = {
415415
auto_close = false,
416416
hijack_cursor = false,
417417
update_cwd = false,
418+
hide_root_folder = false,
418419
update_focused_file = {
419420
enable = false,
420421
update_cwd = false,

lua/nvim-tree/lib.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function M.redraw()
5858
end
5959

6060
local function get_node_at_line(line)
61-
local index = 2
61+
local index = view.View.hide_root_folder and 1 or 2
6262
local function iter(entries)
6363
for _, node in ipairs(entries) do
6464
if index == line then
@@ -101,6 +101,7 @@ end
101101

102102
function M.get_node_at_cursor()
103103
local winnr = view.get_winnr()
104+
local hide_root_folder = view.View.hide_root_folder
104105
if not winnr then
105106
return
106107
end
@@ -111,7 +112,7 @@ function M.get_node_at_cursor()
111112
local help_text = get_node_at_line(line+1)(help_lines)
112113
return {name = help_text}
113114
else
114-
if line == 1 and M.Tree.cwd ~= "/" then
115+
if line == 1 and M.Tree.cwd ~= "/" and not hide_root_folder then
115116
return { name = ".." }
116117
end
117118

@@ -202,7 +203,8 @@ end
202203

203204
function M.set_index_and_redraw(fname)
204205
local i
205-
if M.Tree.cwd == '/' then
206+
local hide_root_folder = view.View.hide_root_folder
207+
if M.Tree.cwd == '/' or hide_root_folder then
206208
i = 0
207209
else
208210
i = 1

lua/nvim-tree/renderer/init.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,9 @@ local function update_draw_data(tree, depth, markers)
266266
["readme.md"] = true,
267267
}
268268

269-
if tree.cwd and tree.cwd ~= '/' then
269+
local hide_root_folder = view.View.hide_root_folder
270+
271+
if tree.cwd and tree.cwd ~= '/' and not hide_root_folder then
270272
local root_name = utils.path_join({
271273
utils.path_remove_trailing(vim.fn.fnamemodify(tree.cwd, root_folder_modifier)),
272274
".."

lua/nvim-tree/view.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ end
99
M.View = {
1010
bufnr = nil,
1111
tabpages = {},
12+
hide_root_folder = false,
1213
winopts = {
1314
relativenumber = false,
1415
number = false,
@@ -144,6 +145,7 @@ function M.setup(opts)
144145
M.View.side = options.side
145146
M.View.width = options.width
146147
M.View.height = options.height
148+
M.View.hide_root_folder = options.hide_root_folder
147149
M.View.auto_resize = opts.auto_resize
148150
if options.mappings.custom_only then
149151
M.View.mappings = options.mappings.list

0 commit comments

Comments
 (0)