This plugin automatically adds text headers to files as flexibly as possible.
It was created with the intention of automatically adding copyright headers to the
top of files, but it really could be used for anything.
This wasn't originally intended to be a plugin, so the source is a bit of a mess.
it started as something that was sitting in my config and was adapted to be shared :)
Configuration is minimal, there are very few options. An example configuration below.
local company_name = "CompanyName"
require('dotherightthing').setup({
filetypes = {
['ps1'] = '# Copyright CompanyName. All rights reserved.',
['cs'] = {
function(cbk)
-- Get the filename from the full path in the callback
local filename = vim.fn.fnamemodify(cbk.match, ':t')
return '// <copyright file="' .. filename .. '" company="' .. company_name .. '">'
end,
'// Copyright (c) ' .. company_name .. '. All rights reserved.',
'// </copyright>',
},
},
debug = false,
})
Flexibility was a very important part of how I constructed this plugin, I wanted
to yield the creation of strings as much as possible back to the setup function.
As such, there are many valid formats of the filetypes configuration.
The filetypes
field takes key value pairs with the key matching the filetype
provided through Neovim's filetype detection. You can find the filetype for any
given buffer by running :lua print(vim.bo.filetype)
within a buffer.
The value is where there are many syntax options. Strings, tables, and functions
are accepted.
- Tables may contain strings, functions or a mix of both.
- Tables, in all scenarios, are interpreted as every entry being a new line.
- Functions must always return either a table of strings, or a string.
- Any function is invoked with the callback provided by Nvim's autocmd's 'command'
If there are any other scenarios that would be helpful to support, I am open
to contributions or suggestions. I think the options provided should cover 99% of
cases.
- Default configurations for popular filetypes with intuitive functions.