fix gitignore feature (#264)

This commit is contained in:
peach lasagna 2021-04-01 02:37:29 +07:00 committed by GitHub
parent d19a6feb24
commit 1f1b25de4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 13 deletions

View File

@ -20,7 +20,7 @@ Plug 'kyazdani42/nvim-tree.lua'
let g:nvim_tree_side = 'right' "left by default
let g:nvim_tree_width = 40 "30 by default
let g:nvim_tree_ignore = [ '.git', 'node_modules', '.cache' ] "empty by default
let g:nvim_tree_gitignore = 2 "0 by default
let g:nvim_tree_gitignore = 1 "0 by default
let g:nvim_tree_auto_open = 1 "0 by default, opens the tree when typing `vim $DIR` or `vim`
let g:nvim_tree_auto_close = 1 "0 by default, closes the tree when it's the last window
let g:nvim_tree_auto_ignore_ft = [ 'startify', 'dashboard' ] "empty by default, don't auto open tree on specific filetypes.

View File

@ -75,8 +75,7 @@ files ignored by git.
Must be:
0: not ignored
1: ignored files from .gitignore
2: ignored files from .gitignore and git exclude
1: ignored files from `git ls-files --others --ignored --exclude-standard --directory`
>
|g:nvim_tree_show_icons| *g:nvim_tree_show_icons*

View File

@ -30,8 +30,8 @@ local function update_root_status(root)
end
end
function M.get_path_gitexclude()
return vim.fn.system("git config --get core.excludesFile")
function M.get_gitexclude()
return vim.fn.system("git ls-files --others --ignored --exclude-standard --directory")
end
function M.reload_roots()

View File

@ -101,20 +101,16 @@ end
local function gen_ignore_check()
local ignore_list = {}
local function add_toignore(path)
local content = utils.read_file(path)
local function add_toignore(content)
for s in content:gmatch("[^\r\n]+") do
ignore_list[s] = true
end
end
if (vim.g.nvim_tree_gitignore or 0) > 0 then
add_toignore('.gitignore')
if (vim.g.nvim_tree_gitignore or 0) == 1 then
add_toignore(git.get_gitexclude())
end
if (vim.g.nvim_tree_gitignore or 0) == 2 then
add_toignore(git.get_path_gitexclude())
end
if vim.g.nvim_tree_ignore and #vim.g.nvim_tree_ignore > 0 then
for _, entry in pairs(vim.g.nvim_tree_ignore) do
ignore_list[entry] = true