Skip to content

feat: add option to hide root dir path #631

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
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2ad3e33
feat: add option to hide root dir path
jim-fx Sep 23, 2021
4d62ac2
Update README.md (#621)
Sep 25, 2021
7f148f1
Only renders the git icon if the icon is not empty (#633)
saviocmc Sep 25, 2021
109122b
chore: refacto setup part 1 (#603)
kyazdani42 Sep 25, 2021
4be0a36
fix: lsp_diagnostics switch reversed. (#635)
wayjam Sep 26, 2021
aa6e674
fix: open view on NvimTreeFindFile
kyazdani42 Sep 26, 2021
5ee7324
chore: lsp diagnostics setup
kyazdani42 Sep 26, 2021
dd880e3
feat: option to set path destination to parent folder when cursor is …
booperlv Sep 26, 2021
c588e96
fix: defer the options check
kyazdani42 Sep 26, 2021
9f7b563
chore/fix: renderer module initializations
kyazdani42 Sep 26, 2021
e19eb5c
fix: remove buffer when replacing window
kyazdani42 Sep 26, 2021
ddd80af
chore: refacto view setup and simplify the code
kyazdani42 Sep 26, 2021
6f35805
fix: remove tip from readme because we can use NvimTreeResize
kyazdani42 Sep 26, 2021
0236b53
Remove duplicate 'nvim-tree-options' tag. (#642)
echasnovski Sep 26, 2021
c73186c
fix: help after refactoring view (#647)
qqshfox Sep 27, 2021
3ed80fd
fix: highlight git new file icon with gitnew not gitdirty
kyazdani42 Sep 27, 2021
08b351a
fix: renderer global options should be loaded on each reload
kyazdani42 Sep 27, 2021
d969239
docfix: remove EOF tag
kyazdani42 Sep 27, 2021
a5724d5
refactor: move options into function
jim-fx Sep 28, 2021
2ec39bc
refactor: move hide_root_folder option out of view options
jim-fx Sep 28, 2021
8cba74a
Merge branch 'master' of https://github.com/kyazdani42/nvim-tree.lua …
jim-fx Sep 28, 2021
8a1d7b1
Merge branch 'kyazdani42-master'
jim-fx Sep 28, 2021
fdd632b
fix: wrong indentations in readme
jim-fx Sep 28, 2021
e1b13f5
fix: make linter happy
jim-fx Sep 30, 2021
e8a0379
Merge branch 'kyazdani42:master' into master
jim-fx Sep 30, 2021
a99ca2a
Merge branch 'master' of github.com:jim-fx/nvim-tree.lua
jim-fx Sep 30, 2021
0022cd7
Merge branch 'master' of https://github.com/kyazdani42/nvim-tree.lua
jim-fx Oct 2, 2021
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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ require'nvim-tree'.setup {
},
-- hijack the cursor in the tree to put it at the start of the filename
hijack_cursor = false,
-- updates the root directory of the tree on `DirChanged` (when your run `:cd` usually)
-- updates the root directory of the tree on `DirChanged` (when your run `:cd` usually)
update_cwd = false,
-- show lsp diagnostics in the signcolumn
lsp_diagnostics = false,
-- Hide the root path of the current folder on top of the tree
hide_root_folder = false,
-- update the focused file on `BufEnter`, un-collapses the folders recursively until it finds the file
update_focused_file = {
-- enables the feature
Expand Down Expand Up @@ -222,6 +224,7 @@ highlight NvimTreeFolderIcon guibg=blue
### Settings

The `list` option in `view.mappings.list` is a table of

```lua
-- key can be either a string or a table of string (lhs)
-- cb is the callback that will be called
Expand All @@ -232,6 +235,7 @@ local list = {
```

These are the default bindings:

```lua
local tree_cb = require'nvim-tree.config'.nvim_tree_callback
-- default mappings
Expand Down
7 changes: 6 additions & 1 deletion doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ function.
open_on_tab = false,
hijack_cursor = false,
update_cwd = false,
hide_root_folder = false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indenting :)

lsp_diagnostics = false,
update_focused_file = {
enable = false,
Expand Down Expand Up @@ -200,7 +201,10 @@ Here is a list of the options available in the setup call:
type: `boolean`
default: false

*nvim-tree.view*
- |hide_root_folder|: hide the path of the current working directory on top of the tree
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

badly resolved, add a *nvim-tree.hide_root_folder* above your option declaration and do not remove the *nvim-tree.view* before the view declaration :)

type: `boolean`
default: false

- |view|: window / buffer setup

- |view.width|: width of the window, can be either a `%` string or
Expand Down Expand Up @@ -547,6 +551,7 @@ applied.

NvimTreeSymlink
NvimTreeFolderName
NvimTreeHideRootFolder
NvimTreeRootFolder
NvimTreeFolderIcon
NvimTreeEmptyFolderName
Expand Down
49 changes: 47 additions & 2 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,15 @@ function M.on_keypress(mode)
return keypress_funcs[mode](node)
end

local hide_root_folder = view.View.hide_root_folder


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too many empty lines here, one suffice :)

if node.name == ".." then
return lib.change_dir("..")
if hide_root_folder then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing or node.name ~= '..'

return lib.unroll_dir(node);
else
return lib.change_dir("..")
end
elseif mode == "cd" and node.entries ~= nil then
return lib.change_dir(lib.get_last_group_node(node).absolute_path)
elseif mode == "cd" then
Expand Down Expand Up @@ -408,7 +415,8 @@ local DEFAULT_OPTS = {
hijack_cursor = false,
update_cwd = false,
lsp_diagnostics = false,
update_focused_file = {
hide_root_folder = false,
update_focused_file = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

badly aligned :)

enable = false,
update_cwd = false,
ignore_list = {}
Expand Down Expand Up @@ -439,6 +447,10 @@ function M.setup(conf)
_config.update_to_buf_dir = opts.update_to_buf_dir
end

if opts.hide_root_folder then
view.View.hide_root_folder = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is a view option, add it to the view config and set it inside the view setup.

end

require'nvim-tree.colors'.setup()
require'nvim-tree.view'.setup(opts.view or {})
require'nvim-tree.diagnostics'.setup(opts)
Expand All @@ -450,4 +462,37 @@ function M.setup(conf)
vim.schedule(function() M.on_enter(opts) end)
end

local function startup_check_new_setup()
local out_config = {
"nvim_tree_disable_netrw",
"nvim_tree_hijack_netrw",
"nvim_tree_auto_open",
"nvim_tree_auto_close",
"nvim_tree_tab_open",
"nvim_tree_hide_root_folder",
"nvim_tree_update_cwd",
"nvim_tree_hijack_cursor",
"nvim_tree_system_open_command",
"nvim_tree_system_open_command_args",
"nvim_tree_follow",
"nvim_tree_follow_update_path",
"nvim_tree_lsp_diagnostics",
"nvim_tree_auto_resize",
"nvim_tree_bindings",
"nvim_tree_disable_keybindings",
"nvim_tree_disable_default_keybindings",
}

local x = vim.tbl_filter(function(v)
return vim.fn.exists('g:'..v) ~= 0
end, out_config)

if #x > 0 then
local msg = "following options are now set in the setup, please read the new documentation for the setup function: "
require'nvim-tree.utils'.echo_warning(msg..table.concat(x, " | "))
end
end

vim.defer_fn(startup_check_new_setup, 1000)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this whole code has been moved to plugin/nvim-tree-startup.lua


return M
12 changes: 10 additions & 2 deletions lua/nvim-tree/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ end

local function get_node_at_line(line)
local index = 2

local hide_root_folder = view.View.hide_root_folder
if hide_root_folder then
index = 1
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

badly indented

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also for more concise reading:
local index = view.View.hide_root_folder and 1 or 2


local function iter(entries)
for _, node in ipairs(entries) do
if index == line then
Expand Down Expand Up @@ -102,6 +108,7 @@ end

function M.get_node_at_cursor()
local winnr = view.get_winnr()
local hide_root_folder = view.View.hide_root_folder
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space missing

if not winnr then
return
end
Expand All @@ -112,7 +119,7 @@ function M.get_node_at_cursor()
local help_text = get_node_at_line(line+1)(help_lines)
return {name = help_text}
else
if line == 1 and M.Tree.cwd ~= "/" then
if line == 1 and M.Tree.cwd ~= "/" and not hide_root_folder then
return { name = ".." }
end

Expand Down Expand Up @@ -205,7 +212,8 @@ end

function M.set_index_and_redraw(fname)
local i
if M.Tree.cwd == '/' then
local hide_root_folder = view.View.hide_root_folder
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space missing here too

if M.Tree.cwd == '/' and hide_root_folder then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this an and and not an or ?

i = 0
else
i = 1
Expand Down
7 changes: 5 additions & 2 deletions lua/nvim-tree/renderer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,17 @@ local picture = {

local function update_draw_data(tree, depth, markers)
local root_folder_modifier = vim.g.nvim_tree_root_folder_modifier or ':~'
local special = vim.g.nvim_tree_special_files or {
local special = vim.g.nvim_tree_special_files or {
["Cargo.toml"] = true,
Makefile = true,
["README.md"] = true,
["readme.md"] = true,
}

if tree.cwd and tree.cwd ~= '/' then

local hide_root_folder = view.View.hide_root_folder

if tree.cwd and tree.cwd ~= '/' and not hide_root_folder then
local root_name = utils.path_join({
utils.path_remove_trailing(vim.fn.fnamemodify(tree.cwd, root_folder_modifier)),
".."
Expand Down
5 changes: 3 additions & 2 deletions lua/nvim-tree/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ end
M.View = {
bufnr = nil,
tabpages = {},
hide_root_folder = false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing space.

winopts = {
relativenumber = false,
number = false,
Expand Down Expand Up @@ -107,7 +108,7 @@ end
local DEFAULT_CONFIG = {
width = 30,
side = 'left',
auto_resize = false,
auto_resize = false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unwanted change

mappings = {
custom_only = false,
list = {}
Expand Down Expand Up @@ -141,7 +142,7 @@ function M.setup(opts)
local options = vim.tbl_deep_extend('force', DEFAULT_CONFIG, opts)
M.View.side = options.side
M.View.width = options.width
M.View.auto_resize = opts.auto_resize
M.View.auto_resize = opts.auto_resize
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bis

if options.mappings.custom_only then
M.View.mappings = options.mappings.list
else
Expand Down