A Neovim plugin to detect properties defined in gitattributes files, including the extended attributes used by the Linguist overrides for GitHub/GitLab.
Using lazy.nvim
{
"davidmh/gitattributes.nvim",
opts = {}
}
The default configuration covers the two use cases I found most useful:
- Setting a filetype for files using the
linguist-language=<language>
attribute. - Revoke write permissions for files matching the
linguist-generated
attribute.
{
---@param data GitAttributesData
on_match = function(data)
if data.attributes["linguist-generated"] then
vim.bo[data.buffer].readonly = true
vim.bo[data.buffer].modifiable = false
end
if data.attributes["linguist-language"] then
vim.bo[data.buffer].filetype = data.attributes["linguist-language"]
end
end
}
The type for the attributes includes only a subset of the attributes defined in the gitattributes documentation, but all the attributes should be available at runtime.