From 9e2f6b6f25f9b79fc99ec9e350d87906d0055ea4 Mon Sep 17 00:00:00 2001 From: Michael <42828375+sarmong@users.noreply.github.com> Date: Fri, 21 Jan 2022 11:48:58 +0200 Subject: [PATCH] feat: add exclude filter list (#878) --- doc/nvim-tree-lua.txt | 5 +++++ lua/nvim-tree.lua | 3 ++- lua/nvim-tree/populate.lua | 9 +++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index b4b1023b..3acd75cd 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -338,6 +338,11 @@ Here is a list of the options available in the setup call: type: `{string}` default: `{}` + - |filters.exclude|: list of directories or files to exclude from filtering + (will always be shown) + type: `{string}` + default: `{}` + *nvim-tree.trash* |trash|: configuration options for trashing diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 291224a2..6c20b0c6 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -441,7 +441,8 @@ local DEFAULT_OPTS = { }, filters = { dotfiles = false, - custom_filter = {} + custom_filter = {}, + exclude = {} }, git = { enable = true, diff --git a/lua/nvim-tree/populate.lua b/lua/nvim-tree/populate.lua index 7bd858ba..c014a9f6 100644 --- a/lua/nvim-tree/populate.lua +++ b/lua/nvim-tree/populate.lua @@ -5,6 +5,7 @@ local utils = require'nvim-tree.utils' local M = { ignore_list = {}, + exclude_list = {}, is_windows = vim.fn.has('win32') == 1 } @@ -122,6 +123,12 @@ end local function should_ignore(path) local basename = utils.path_basename(path) + for _, entry in ipairs(M.exclude_list) do + if path:match(entry) then + return false + end + end + if M.config.filter_dotfiles then if basename:sub(1, 1) == '.' then return true @@ -353,6 +360,8 @@ function M.setup(opts) filter_dotfiles = opts.filters.dotfiles, } + M.exclude_list = opts.filters.exclude + local custom_filter = opts.filters.custom if custom_filter and #custom_filter > 0 then for _, entry in pairs(custom_filter) do