-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(nvim) Add script that injects AI-generated commit messages
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
local inject_commit_message = function() | ||
-- `vim.ui.select` function's behavior is asyncronous. | ||
-- | ||
-- So, In order to generate commit message by selected language, | ||
-- we have to place `generate_commit_message` inside of `vim.ui.select` function's callback | ||
vim.ui.select( | ||
{"korean", "english"}, | ||
{ | ||
prompt = "Select language: ", | ||
}, | ||
function(language) | ||
if language ~= nil then | ||
local prompt = require('utilities.prompt-engineering').generate_commit_message(language) | ||
require("neoai").context_inject(prompt, nil) | ||
end | ||
end | ||
) | ||
end | ||
|
||
vim.api.nvim_create_user_command("InjectCommitMessage", inject_commit_message, {}) |
21 changes: 21 additions & 0 deletions
21
private_dot_config/nvim/lua/utilities/prompt-engineering.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
local M = {} | ||
|
||
M.generate_commit_message = function(language) | ||
local prompt = [[ | ||
Using the following git diff generate a consise and | ||
clear git commit message, with a short title summary | ||
that is 75 characters or less | ||
]] .. " and you should generate commit message in " .. language .. [[: | ||
]] .. [[ | ||
``` | ||
]] .. vim.fn.system("git diff --cached") | ||
.. [[ | ||
``` | ||
And you shoud give me commit message immediately. | ||
And you don't need to explain unnecessary things. | ||
]] | ||
|
||
return prompt | ||
end | ||
|
||
return M |