Reports whether a path matches Gitignore rules in Neovim.
- Neovim 0.10+
git
{
"so1ve/tiny-gitignore.nvim",
opts = {},
}vim.pack.add({
{ src = "https://github.com/so1ve/tiny-gitignore.nvim" },
}, { confirm = false })
require("tiny-gitignore").setup()Use is_ignored() in an explorer filter and refresh the view when the cache
changes:
local gitignore = require("tiny-gitignore")
local opts = {
content = {
filter = function(entry)
return not gitignore.is_ignored(entry.path)
end,
},
}
vim.api.nvim_create_autocmd("User", {
pattern = "TinyGitignoreCacheUpdated",
callback = function()
require("mini.files").refresh(opts)
end,
})The first lookup starts an asynchronous load and returns false until it
finishes.
require("tiny-gitignore").setup({
event = "TinyGitignoreCacheUpdated",
git = "git",
})| Option | Default | Description |
|---|---|---|
event |
"TinyGitignoreCacheUpdated" |
User event emitted after a repository cache changes. |
git |
"git" |
Git executable. |
Installs the refresh autocmds and loads the current working directory's repository cache.
Returns whether path is ignored by the repository that contains it. Checks
each ancestor directory.
require("tiny-gitignore").is_ignored("/path/to/repo/build/output.log")Reloads the cache for the repository that contains path. Without a path, uses
the current working directory.
require("tiny-gitignore").refresh(vim.api.nvim_buf_get_name(0))Ignored paths come from git ls-files --ignored --others --exclude-standard, so
Git applies nested .gitignore, .git/info/exclude, and global exclude rules.
nvim --headless -u NONE -i NONE -l tests/tiny-gitignore.lua