Skip to content

About

Check whether paths match Gitignore rules in Neovim.

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

tiny-gitignore.nvim

Reports whether a path matches Gitignore rules in Neovim.

Requirements

  • Neovim 0.10+
  • git

Installation

lazy.nvim

{
  "so1ve/tiny-gitignore.nvim",
  opts = {},
}

vim.pack

vim.pack.add({
  { src = "https://github.com/so1ve/tiny-gitignore.nvim" },
}, { confirm = false })

require("tiny-gitignore").setup()

Usage

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.

Configuration

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.

API

setup(opts?)

Installs the refresh autocmds and loads the current working directory's repository cache.

is_ignored(path)

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")

refresh(path?)

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))

Notes

Ignored paths come from git ls-files --ignored --others --exclude-standard, so Git applies nested .gitignore, .git/info/exclude, and global exclude rules.

Tests

nvim --headless -u NONE -i NONE -l tests/tiny-gitignore.lua

📝 License

MIT. Made with ❤️ by Ray

About

Check whether paths match Gitignore rules in Neovim.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages