A plugin designed to make committing a bit easier.
With this plugin, you can set fugitive to automatically write custom commits whenever you save, when you stop moving the cursor, or during a custom event.
To install with Lazy.nvim:
{
'AuLaSW/autocommit.nvim',
dependecies = {
-- whatever git handler you use, I use fugitive
'tpope/vim-fugitive'
},
config = function (...)
require('autocommit').setup()
end
}
That will set up the work. You will need to create a keymapping
such as the following that calls hook()
from the require
command:
vim.keymap.set(
'n',
'<Leader>ac',
function (...)
require('autocommit').hook()
end
)
The hook()
command takes no arguments and sets an autocommand
that runs create_commit()
during certain events.
The default settings are as follows:
require('autocommit').setup(
{
---Should not be overwritten; an enum class used for
---commit.when
---@type table
actions = {
SAVE = 0,
WAIT = 1,
CUSTOM = 2, },
---@type table
commit = {
---When to commit.
---@type Actions
when = ACTIONS.SAVE,
---The header generated at each commit
---@type fun()
---@return string
header = function ()
return os.date('[Autocommit] - %c')
end,
---The body generated at each commit
body = function ()
return 'This was an automatic commit generated by autocommit.nvim.'
end,
},
---List of events used in custom commit.when
---@type {string}
events = {
'BufWritePost'
},
---Set up the autocommand to run on the buffer
---@type fun()
hook = hook,
---@type fun()
create_commit = create_commit,
}
)
If you are not running fugitive, it is recommended that you
overwrite create_commit()
with your own function so that
autocommit.nvim can interact with your git handler.
In the future, I would like to add support for more git handlers and have them be selectable within the options.