add Gitignore (#251)

This commit is contained in:
peach lasagna 2021-03-31 01:11:25 +07:00 committed by GitHub
parent 709d6b968b
commit eadead6072
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 0 deletions

View File

@ -20,6 +20,7 @@ Plug 'kyazdani42/nvim-tree.lua'
let g:nvim_tree_side = 'right' | 'left' "left by default let g:nvim_tree_side = 'right' | 'left' "left by default
let g:nvim_tree_width = 40 "30 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_ignore = [ '.git', 'node_modules', '.cache' ] "empty by default
let g:nvim_tree_gitignore = 2 "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_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_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. let g:nvim_tree_auto_ignore_ft = {'startify', 'dashboard'} "empty by default, don't auto open tree on specific filetypes.

View File

@ -68,6 +68,17 @@ useful to hide large data/cache folders.
> >
example: let g:nvim_tree_ignore = [ '.git', 'node_modules' ] example: let g:nvim_tree_ignore = [ '.git', 'node_modules' ]
|g:nvim_tree_gitignore| *g:nvim_tree_gitignore*
Determines whether to include in g:nvim_tree_ignore
files ignored by git.
Must be:
0: not ignored
1: ignored files from .gitignore
2: ignored files from .gitignore and git exclude
>
|g:nvim_tree_show_icons| *g:nvim_tree_show_icons* |g:nvim_tree_show_icons| *g:nvim_tree_show_icons*
Dictionary, if your terminal or font doesn't support certain unicode Dictionary, if your terminal or font doesn't support certain unicode

View File

@ -30,6 +30,10 @@ local function update_root_status(root)
end end
end end
function M.get_path_gitexclude()
return vim.fn.system("git config --get core.excludesFile")
end
function M.reload_roots() function M.reload_roots()
for root, status in pairs(roots) do for root, status in pairs(roots) do
if status ~= not_git then if status ~= not_git then

View File

@ -100,6 +100,21 @@ end
local function gen_ignore_check() local function gen_ignore_check()
local ignore_list = {} local ignore_list = {}
local function add_toignore(path)
local content = utils.read_file(path)
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')
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 if vim.g.nvim_tree_ignore and #vim.g.nvim_tree_ignore > 0 then
for _, entry in pairs(vim.g.nvim_tree_ignore) do for _, entry in pairs(vim.g.nvim_tree_ignore) do
ignore_list[entry] = true ignore_list[entry] = true

View File

@ -1,4 +1,5 @@
local M = {} local M = {}
local uv = vim.loop -- or require("luv") ? i dont understand
local api = vim.api local api = vim.api
function M.path_to_matching_str(path) function M.path_to_matching_str(path)
@ -11,6 +12,16 @@ function M.echo_warning(msg)
api.nvim_command('echohl None') api.nvim_command('echohl None')
end end
function M.read_file(path)
local fd = uv.fs_open(path, "r", 438)
if not fd then return '' end
local stat = uv.fs_fstat(fd)
if not stat then return '' end
local data = uv.fs_read(fd, stat.size, 0)
uv.fs_close(fd)
return data or ''
end
local path_separator = package.config:sub(1,1) local path_separator = package.config:sub(1,1)
function M.path_join(paths) function M.path_join(paths)
return table.concat(paths, path_separator) return table.concat(paths, path_separator)