Skip to content

A Neovim plugin to detect properties defined in .gitattributes

Notifications You must be signed in to change notification settings

davidmh/gitattributes.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

gitattributes.nvim

A Neovim plugin to detect properties defined in gitattributes files, including the extended attributes used by the Linguist overrides for GitHub/GitLab.

Installation

Using lazy.nvim

{
  "davidmh/gitattributes.nvim",
  opts = {}
}

Default config

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
}

Notes

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.

About

A Neovim plugin to detect properties defined in .gitattributes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages