From 206241e451c12f78969ff5ae53af45616ffc9b72 Mon Sep 17 00:00:00 2001 From: Fritiof Rusck Date: Tue, 11 Jun 2024 04:49:48 +0200 Subject: [PATCH] feat: add options always_show_by_pattern (#1444) --- README.md | 3 +++ doc/neo-tree.txt | 7 +++++++ lua/neo-tree/defaults.lua | 3 +++ lua/neo-tree/sources/common/file-items.lua | 5 +++++ lua/neo-tree/sources/filesystem/init.lua | 2 +- 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d93515a8..ab5b4180 100644 --- a/README.md +++ b/README.md @@ -305,6 +305,9 @@ use { always_show = { -- remains visible even if other settings would normally hide it --".gitignored", }, + always_show_by_pattern = { -- uses glob style patterns + --".env*", + }, never_show = { -- remains hidden even if visible is toggled to true, this overrides always_show --".DS_Store", --"thumbs.db" diff --git a/doc/neo-tree.txt b/doc/neo-tree.txt index be49813b..e66325ce 100644 --- a/doc/neo-tree.txt +++ b/doc/neo-tree.txt @@ -940,6 +940,9 @@ highlight group which will be applied when they are visible, see always_show = { -- remains visible even if other settings would normally hide it --".gitignored", }, + always_show_by_pattern = { -- uses glob style patterns + --".env*", + }, never_show = { -- remains hidden even if visible is toggled to true, this overrides always_show --".DS_Store", --"thumbs.db", @@ -973,6 +976,10 @@ The `always_show` option is a list of file/folder names that will always be visible, even if other settings would normally hide it. This section takes precedence over all other options except for `never_show`. +the `always_show_by_pattern` option is a list of file/folder patterns that +always will be visible. This section takes precedence over all other options +except `never_show`. + The `never_show` option is the same as `hide_by_name`, except that those items will remain hidden even if you toggle `visible` to true. This section takes precedence over the others. diff --git a/lua/neo-tree/defaults.lua b/lua/neo-tree/defaults.lua index 733dcc07..61a195f7 100644 --- a/lua/neo-tree/defaults.lua +++ b/lua/neo-tree/defaults.lua @@ -477,6 +477,9 @@ local config = { always_show = { -- remains visible even if other settings would normally hide it --".gitignored", }, + always_show_by_pattern = { -- uses glob style patterns + --".env*", + }, never_show = { -- remains hidden even if visible is toggled to true, this overrides always_show --".DS_Store", --"thumbs.db" diff --git a/lua/neo-tree/sources/common/file-items.lua b/lua/neo-tree/sources/common/file-items.lua index 1d040421..3e4a7a75 100644 --- a/lua/neo-tree/sources/common/file-items.lua +++ b/lua/neo-tree/sources/common/file-items.lua @@ -167,6 +167,11 @@ function create_item(context, path, _type, bufnr) if f.always_show[name] then item.filtered_by = item.filtered_by or {} item.filtered_by.always_show = true + else + if utils.is_filtered_by_pattern(f.always_show_by_pattern, path, name) then + item.filtered_by = item.filtered_by or {} + item.filtered_by.always_show = true + end end if f.hide_by_name[name] then item.filtered_by = item.filtered_by or {} diff --git a/lua/neo-tree/sources/filesystem/init.lua b/lua/neo-tree/sources/filesystem/init.lua index a6a3e4b2..7101864c 100644 --- a/lua/neo-tree/sources/filesystem/init.lua +++ b/lua/neo-tree/sources/filesystem/init.lua @@ -260,7 +260,7 @@ M.setup = function(config, global_config) config.filtered_items = config.filtered_items or {} config.enable_git_status = global_config.enable_git_status - for _, key in ipairs({ "hide_by_pattern", "never_show_by_pattern" }) do + for _, key in ipairs({ "hide_by_pattern", "always_show_by_pattern", "never_show_by_pattern" }) do local list = config.filtered_items[key] if type(list) == "table" then for i, pattern in ipairs(list) do