Skip to content

Commit 9e0d6bb

Browse files
committed
feat(files)!: add hide_by_name, show hidden items in new highlight (#172)
closes #148, closes #149 BREAKING CHANGE: refactor `filters` config options.
1 parent 6c84fef commit 9e0d6bb

File tree

16 files changed

+334
-97
lines changed

16 files changed

+334
-97
lines changed

.github/workflows/protect_release_branches.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
pull_request:
99
branches:
1010
- 'v1.x'
11-
- 'v2.x'
11+
# - 'v2.x'
1212

1313
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
1414
jobs:

README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Example for packer:
4444
```lua
4545
use {
4646
"nvim-neo-tree/neo-tree.nvim",
47-
branch = "v1.x",
47+
branch = "v2.x",
4848
requires = {
4949
"nvim-lua/plenary.nvim",
5050
"kyazdani42/nvim-web-devicons", -- not strictly required, but recommended
@@ -86,13 +86,23 @@ use {
8686
},
8787
},
8888
filesystem = {
89-
filters = { --These filters are applied to both browsing and searching
90-
show_hidden = false,
91-
respect_gitignore = true,
89+
filtered_items = {
90+
visible = false, -- when true, they will just be displayed differently than normal items
91+
hide_dotfiles = true,
92+
hide_gitignored = true,
93+
hide_by_name = {
94+
".DS_Store",
95+
"thumbs.db"
96+
--"node_modules"
97+
},
98+
never_show = { -- remains hidden even if visible is toggled to true
99+
--".DS_Store",
100+
--"thumbs.db"
101+
},
92102
},
93-
follow_current_file = false, -- This will find and focus the file in the active buffer every
103+
follow_current_file = true, -- This will find and focus the file in the active buffer every
94104
-- time the current file is changed while the tree is open.
95-
use_libuv_file_watcher = false, -- This will use the OS level file watchers
105+
use_libuv_file_watcher = true, -- This will use the OS level file watchers
96106
-- to detect changes instead of relying on nvim autocmd events.
97107
hijack_netrw_behavior = "open_default", -- netrw disabled, opening a directory opens neo-tree
98108
-- in whatever position is specified in window.position

doc/neo-tree.txt

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Mappings .................... |neo-tree-mappings|
1010
Filter .................... |neo-tree-filter|
1111
Configuration ............... |neo-tree-configuration|
1212
Setup ..................... |neo-tree-setup|
13+
Filtered Items ............ |neo-tree-filtered-items|
1314
Hijack Netrw Behavior ..... |neo-tree-netrw-hijack|
1415
Component Configs ......... |neo-tree-component-configs|
1516
Git Status ................ |neo-tree-git-status|
@@ -176,14 +177,11 @@ p = paste_from_clipboard: Copy/move each marked file in the to the
176177

177178

178179
VIEW CHANGES *neo-tree-view-changes*
179-
H = toggle_hidden: Toggle whether hidden files (.*) are shown or not.
180+
H = toggle_hidden: Toggle whether hidden (filtered items) are shown or not.
180181

181-
I = toggle_gitignore: Toggle whether the gitignore file is
182-
respected.
183-
184-
R = refresh: Rescan the filesystem and redraw the tree. Changes
185-
made within nvim should be detected automatically, but
186-
this is useful for changes made elsewhere.
182+
R = refresh: Rescan the filesystem and redraw the tree. Changes made
183+
within nvim should be detected automatically, but this is
184+
useful for changes made elsewhere.
187185

188186

189187
FILTER *neo-tree-filter*
@@ -324,7 +322,44 @@ existing global mappings to work.
324322
Run |NeoTreePasteConfig| to dump the fully commented default config in your
325323
current file. Even if you don't want to use that config as your starting point,
326324
you still may want to dump it to a blank .lua file just to read it as
327-
documentation.
325+
documentation. SOME OPTIONS ARE ONLY DOCUMENTED IN THE DEFAULT CONFIG!
326+
327+
328+
FILTERED ITEMS *neo-tree-filtered-items*
329+
330+
The `filesystem` source has a `filtered_items` section in it's config that
331+
allows you to specify what files and folders should be hidden. By default, any
332+
item identified by these filters will not be visible, but that visibility can
333+
be toggled on and off with a command. Each type of filter has a corresponding
334+
highlight group which will be applied when they are visible, see
335+
|neo-tree-highlights| for details. The following options are available:
336+
337+
>
338+
require("neo-tree").setup({
339+
filesystem = {
340+
filtered_items = {
341+
visible = false, -- when true, they will just be displayed differently than normal items
342+
hide_dotfiles = true,
343+
hide_gitignored = true,
344+
hide_by_name = {
345+
".DS_Store",
346+
"thumbs.db"
347+
--"node_modules"
348+
},
349+
never_show = { -- remains hidden even if visible is toggled to true
350+
--".DS_Store",
351+
--"thumbs.db"
352+
},
353+
},
354+
}
355+
})
356+
<
357+
The `visible` option just defines the default value. This value is toggled by
358+
the "toggle_hidden" command, which is mapped to H by default.
359+
360+
The `never_show` option is the same as `hide_by_name`, except that those items
361+
will remain hidden even if you toggle `visible` to true. This section takes
362+
precedence over the others.
328363

329364

330365
NETRW HIJACK BEHAVIOR *neo-tree-netrw-hijack*
@@ -484,12 +519,12 @@ exist, they will be created.
484519
NeoTreeBufferNumber The buffer number shown in the buffers source.
485520
NeoTreeCursorLine |hi-CursorLine| override in Neo-tree window.
486521
NeoTreeDimText Greyed out text used in various places.
487-
NeoTreeDirectoryName Directory name.
488522
NeoTreeDirectoryIcon Directory icon.
523+
NeoTreeDirectoryName Directory name.
524+
NeoTreeDotfile Used for icons and names when dotfiles are filtered.
489525
NeoTreeFileIcon File icon, when not overriden by devicons.
490526
NeoTreeFileName File name, when not overwritten by another status.
491527
NeoTreeFileNameOpened File name when the file is open. Not used yet.
492-
NeoTreeSymbolicLinkTarget Symbolic link target.
493528
NeoTreeFilterTerm The filter term, as displayed in the root node.
494529
NeoTreeFloatBorder The border for pop-up windows.
495530
NeoTreeFloatTitle Used for the title text of pop-ups when the border-style
@@ -499,13 +534,18 @@ NeoTreeTitleBar Used for the title bar of pop-ups, when the border-sty
499534
is set to "NC". This is derived from NeoTreeFloatBorder.
500535
NeoTreeGitAdded File name when the git status is added.
501536
NeoTreeGitConflict File name when the git status is conflict.
537+
NeoTreeGitIgnored File name when the git status is ignored.
502538
NeoTreeGitModified File name when the git status is modified.
503539
NeoTreeGitUntracked File name when the git status is untracked.
540+
NeoTreeHiddenByName Used for icons and names when `hide_by_name` is used.
541+
NeoTreeIndentMarker The style of indentation markers (guides). By default,
542+
the "Normal" highlight is used.
504543
NeoTreeNormal |hl-Normal| override in Neo-tree window.
505544
NeoTreeNormalNC |hi-NormalNC| override in Neo-tree window.
506545
NeoTreeRootName The name of the root node.
507-
NeoTreeIndentMarker The style of indentation markers (guides). By default,
508-
the "Normal" highlight is used.
546+
NeoTreeSymbolicLinkTarget Symbolic link target.
547+
NeoTreeTitleBar Used for the title bar of pop-ups, when the border-style
548+
is set to "NC". This is derived from NeoTreeFloatBorder.
509549

510550

511551
EVENTS *neo-tree-events*

lua/neo-tree.lua

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,27 @@ end
523523
M.setup = function(config, is_auto_config)
524524
local default_config = vim.deepcopy(defaults)
525525
config = vim.deepcopy(config or {})
526+
527+
local messages = require("neo-tree.deprecations").migrate(config)
528+
if #messages > 0 then
529+
for i, message in ipairs(messages) do
530+
messages[i] = " * " .. message
531+
end
532+
table.insert(messages, 1, "# Neo-tree configuration has been updated. Please review the changes below.")
533+
local buf = vim.api.nvim_create_buf(false, true)
534+
vim.api.nvim_buf_set_lines(buf, 0, -1, false, messages)
535+
vim.api.nvim_buf_set_option(buf, "buftype", "nofile")
536+
vim.api.nvim_buf_set_option(buf, "bufhidden", "wipe")
537+
vim.api.nvim_buf_set_option(buf, "buflisted", false)
538+
vim.api.nvim_buf_set_option(buf, "swapfile", false)
539+
vim.api.nvim_buf_set_option(buf, "modifiable", false)
540+
vim.api.nvim_buf_set_option(buf, "filetype", "markdown")
541+
vim.defer_fn(function ()
542+
vim.cmd("split")
543+
vim.api.nvim_win_set_buf(0, buf)
544+
end, 100)
545+
end
546+
526547
if config.log_level ~= nil then
527548
M.set_log_level(config.log_level)
528549
end

lua/neo-tree/defaults.lua

Lines changed: 57 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,67 @@ local config = {
7272
},
7373
},
7474
filesystem = {
75+
bind_to_cwd = true, -- true creates a 2-way binding between vim's cwd and neo-tree's root
76+
-- The renderer section provides the renderers that will be used to render the tree.
77+
-- The first level is the node type.
78+
-- For each node type, you can specify a list of components to render.
79+
-- Components are rendered in the order they are specified.
80+
-- The first field in each component is the name of the function to call.
81+
-- The rest of the fields are passed to the function as the "config" argument.
82+
filtered_items = {
83+
visible = false, -- when true, they will just be displayed differently than normal items
84+
hide_dotfiles = true,
85+
hide_gitignored = true,
86+
hide_by_name = {
87+
".DS_Store",
88+
"thumbs.db"
89+
--"node_modules"
90+
},
91+
never_show = { -- remains hidden even if visible is toggled to true
92+
--".DS_Store",
93+
--"thumbs.db"
94+
},
95+
gitignore_source = "git check-ignored", -- or "git status", which may be faster in some repos
96+
},
97+
find_by_full_path_words = false, -- `false` means it only searches the tail of a path.
98+
-- `true` will change the filter into a full path
99+
-- search with space as an implicit ".*", so
100+
-- `fi init`
101+
-- will match: `./sources/filesystem/init.lua
102+
--find_command = "fd",
103+
--find_args = { -- you can specify extra args to pass to the find command.
104+
-- "--exclude", ".git",
105+
-- "--exclude", "node_modules"
106+
--},
107+
---- or use a function instead of list of strings
108+
--find_args = function(cmd, path, search_term, args)
109+
-- if cmd ~= "fd" then
110+
-- return args
111+
-- end
112+
-- --maybe you want to force the filter to always include hidden files:
113+
-- table.insert(args, "--hidden")
114+
-- -- but no one ever wants to see .git files
115+
-- table.insert(args, "--exclude")
116+
-- table.insert(args, ".git")
117+
-- -- or node_modules
118+
-- table.insert(args, "--exclude")
119+
-- table.insert(args, "node_modules")
120+
-- --here is where it pays to use the function, you can exclude more for
121+
-- --short search terms, or vary based on the directory
122+
-- if string.len(search_term) < 4 and path == "/home/cseickel" then
123+
-- table.insert(args, "--exclude")
124+
-- table.insert(args, "Library")
125+
-- end
126+
-- return args
127+
--end,
128+
search_limit = 50, -- max number of search results when using filters
129+
follow_current_file = false, -- This will find and focus the file in the active buffer every time
130+
-- the current file is changed while the tree is open.
75131
hijack_netrw_behavior = "open_default", -- netrw disabled, opening a directory opens neo-tree
76132
-- in whatever position is specified in window.position
77133
-- "open_split", -- netrw disabled, opening a directory opens within the
78134
-- window like netrw would, regardless of window.position
79135
-- "disabled", -- netrw left alone, neo-tree does not handle opening dirs
80-
follow_current_file = false, -- This will find and focus the file in the active buffer every time
81-
-- the current file is changed while the tree is open.
82136
use_libuv_file_watcher = false, -- This will use the OS level file watchers to detect changes
83137
-- instead of relying on nvim autocmd events.
84138
window = { -- see https://github.com/MunifTanjim/nui.nvim/tree/main/lua/nui/popup for
@@ -123,50 +177,6 @@ local config = {
123177
["q"] = "close_window",
124178
},
125179
},
126-
find_by_full_path_words = false, -- `false` means it only searches the tail of a path.
127-
-- `true` will change the filter into a full path
128-
-- search with space as an implicit ".*", so
129-
-- `fi init`
130-
-- will match: `./sources/filesystem/init.lua
131-
--find_command = "fd",
132-
--find_args = { -- you can specify extra args to pass to the find command.
133-
-- "--exclude", ".git",
134-
-- "--exclude", "node_modules"
135-
--},
136-
---- or use a function instead of list of strings
137-
--find_args = function(cmd, path, search_term, args)
138-
-- if cmd ~= "fd" then
139-
-- return args
140-
-- end
141-
-- --maybe you want to force the filter to always include hidden files:
142-
-- table.insert(args, "--hidden")
143-
-- -- but no one ever wants to see .git files
144-
-- table.insert(args, "--exclude")
145-
-- table.insert(args, ".git")
146-
-- -- or node_modules
147-
-- table.insert(args, "--exclude")
148-
-- table.insert(args, "node_modules")
149-
-- --here is where it pays to use the function, you can exclude more for
150-
-- --short search terms, or vary based on the directory
151-
-- if string.len(search_term) < 4 and path == "/home/cseickel" then
152-
-- table.insert(args, "--exclude")
153-
-- table.insert(args, "Library")
154-
-- end
155-
-- return args
156-
--end,
157-
search_limit = 50, -- max number of search results when using filters
158-
filters = {
159-
show_hidden = false,
160-
respect_gitignore = true,
161-
gitignore_source = "git status", -- or "git check-ignored", which may be faster in some repos
162-
},
163-
bind_to_cwd = true, -- true creates a 2-way binding between vim's cwd and neo-tree's root
164-
-- The renderer section provides the renderers that will be used to render the tree.
165-
-- The first level is the node type.
166-
-- For each node type, you can specify a list of components to render.
167-
-- Components are rendered in the order they are specified.
168-
-- The first field in each component is the name of the function to call.
169-
-- The rest of the fields are passed to the function as the "config" argument.
170180
renderers = {
171181
directory = {
172182
{ "indent" },
@@ -199,6 +209,7 @@ local config = {
199209
},
200210
},
201211
buffers = {
212+
bind_to_cwd = true,
202213
window = {
203214
position = "left",
204215
width = 40,
@@ -219,7 +230,6 @@ local config = {
219230
["bd"] = "buffer_delete",
220231
},
221232
},
222-
bind_to_cwd = true,
223233
renderers = {
224234
directory = {
225235
{ "indent" },

lua/neo-tree/deprecations.lua

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
local utils = require "neo-tree.utils"
2+
3+
local migrate = function (config)
4+
local messages = {}
5+
6+
local moved = function (old, new, converter)
7+
local exising = utils.get_value(config, old)
8+
if type(exising) ~= "nil" then
9+
if type(converter) == "function" then
10+
exising = converter(exising)
11+
end
12+
utils.set_value(config, new, exising)
13+
config[old] = nil
14+
messages[#messages + 1] = string.format("The `%s` option has been deprecated, please use `%s` instead.", old, new)
15+
end
16+
end
17+
18+
local opposite = function (value)
19+
return not value
20+
end
21+
22+
moved("filesystem.filters", "filesystem.filtered_items")
23+
moved("filesystem.filters.show_hidden", "filesystem.filtered_items.hide_dotfiles", opposite)
24+
moved("filesystem.filters.respect_gitignore", "filesystem.filtered_items.hide_gitignored")
25+
moved("filesystem.filters.gitignore_source", "filesystem.filtered_items.gitignore_source")
26+
27+
return messages
28+
end
29+
30+
return {
31+
migrate = migrate
32+
}

lua/neo-tree/setup/init.lua

Whitespace-only changes.

0 commit comments

Comments
 (0)