Skip to content

Commit eadead6

Browse files
authored
add Gitignore (#251)
1 parent 709d6b9 commit eadead6

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Plug 'kyazdani42/nvim-tree.lua'
2020
let g:nvim_tree_side = 'right' | 'left' "left by default
2121
let g:nvim_tree_width = 40 "30 by default
2222
let g:nvim_tree_ignore = [ '.git', 'node_modules', '.cache' ] "empty by default
23+
let g:nvim_tree_gitignore = 2 "0 by default
2324
let g:nvim_tree_auto_open = 1 "0 by default, opens the tree when typing `vim $DIR` or `vim`
2425
let g:nvim_tree_auto_close = 1 "0 by default, closes the tree when it's the last window
2526
let g:nvim_tree_auto_ignore_ft = {'startify', 'dashboard'} "empty by default, don't auto open tree on specific filetypes.

doc/nvim-tree-lua.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ useful to hide large data/cache folders.
6868
>
6969
example: let g:nvim_tree_ignore = [ '.git', 'node_modules' ]
7070
71+
|g:nvim_tree_gitignore| *g:nvim_tree_gitignore*
72+
73+
Determines whether to include in g:nvim_tree_ignore
74+
files ignored by git.
75+
76+
Must be:
77+
0: not ignored
78+
1: ignored files from .gitignore
79+
2: ignored files from .gitignore and git exclude
80+
81+
>
7182
|g:nvim_tree_show_icons| *g:nvim_tree_show_icons*
7283

7384
Dictionary, if your terminal or font doesn't support certain unicode

lua/nvim-tree/git.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ local function update_root_status(root)
3030
end
3131
end
3232

33+
function M.get_path_gitexclude()
34+
return vim.fn.system("git config --get core.excludesFile")
35+
end
36+
3337
function M.reload_roots()
3438
for root, status in pairs(roots) do
3539
if status ~= not_git then

lua/nvim-tree/populate.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,21 @@ end
100100

101101
local function gen_ignore_check()
102102
local ignore_list = {}
103+
104+
local function add_toignore(path)
105+
local content = utils.read_file(path)
106+
for s in content:gmatch("[^\r\n]+") do
107+
ignore_list[s] = true
108+
end
109+
end
110+
111+
if (vim.g.nvim_tree_gitignore or 0) > 0 then
112+
add_toignore('.gitignore')
113+
end
114+
if (vim.g.nvim_tree_gitignore or 0) == 2 then
115+
add_toignore(git.get_path_gitexclude())
116+
end
117+
103118
if vim.g.nvim_tree_ignore and #vim.g.nvim_tree_ignore > 0 then
104119
for _, entry in pairs(vim.g.nvim_tree_ignore) do
105120
ignore_list[entry] = true

lua/nvim-tree/utils.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local M = {}
2+
local uv = vim.loop -- or require("luv") ? i dont understand
23
local api = vim.api
34

45
function M.path_to_matching_str(path)
@@ -11,6 +12,16 @@ function M.echo_warning(msg)
1112
api.nvim_command('echohl None')
1213
end
1314

15+
function M.read_file(path)
16+
local fd = uv.fs_open(path, "r", 438)
17+
if not fd then return '' end
18+
local stat = uv.fs_fstat(fd)
19+
if not stat then return '' end
20+
local data = uv.fs_read(fd, stat.size, 0)
21+
uv.fs_close(fd)
22+
return data or ''
23+
end
24+
1425
local path_separator = package.config:sub(1,1)
1526
function M.path_join(paths)
1627
return table.concat(paths, path_separator)

0 commit comments

Comments
 (0)