Compare commits
10
Commits
ffd3fb62f6
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2add9d2a8c | ||
|
|
213a39f816 | ||
|
|
52cb2c9046 | ||
|
|
30a44756ff | ||
|
|
3015299545 | ||
|
|
ffe3dd73ff | ||
|
|
084d0f21cd | ||
|
|
3b005ab8b4 | ||
|
|
182c6615ab | ||
|
|
2c03780bf5 |
No files matched your search
@@ -1,5 +1,48 @@
|
||||
# Neovim mokey-alert
|
||||
# mokey-alert.nvim
|
||||
|
||||
## WIP
|
||||
[](https://github.com/dqnid/monkey-alert.nvim/releases)
|
||||
[](https://www.wtfpl.net/about/)
|
||||
|
||||
Git line blame by mail.
|
||||
|
||||
## 🔧 Options
|
||||
|
||||
- `blame_text_color_hex`: hex color to use as foreground.
|
||||
- `monkey_mail_list`: list of github account emails separated by a single comma ",".
|
||||
- `blame_text`: string with the text that will appear on the blame.
|
||||
- `blame_position`: 'eol' or 'overlay' or 'right_align'.
|
||||
- `auto_attach`: whether or not create an autocmd to blame the current line automatically.
|
||||
|
||||
## 🐾 Usage
|
||||
|
||||
### 💤 Lazyvim
|
||||
|
||||
```lua
|
||||
{
|
||||
"dqnid/monkey-alert.nvim",
|
||||
name = "monkey-alert",
|
||||
opts = {
|
||||
monkey_mail_list = "john@doe.org,another@dude.me",
|
||||
blame_text_color_hex = "#c0ffee",
|
||||
blame_text = "- Monkey alert 🐒",
|
||||
blame_position = "eol",
|
||||
auto_attach = false
|
||||
},
|
||||
},
|
||||
```
|
||||
|
||||
## 🎬 Example
|
||||
|
||||
<img width="715" height="291" alt="monkey-alert" src="https://github.com/user-attachments/assets/f979954e-53b7-473b-a55e-7b8c722825e7" />
|
||||
|
||||
## 🚨 Known issues
|
||||
|
||||
- [x] Error on non-git files.
|
||||
- [ ] Performance: the autocmd should not be processed on non-git files, to this date it is simply not displayed but a `$ git log` is run.
|
||||
|
||||
## Brain made
|
||||
|
||||
1. I don't hate AIs,
|
||||
2. I love humans!
|
||||
|
||||

|
||||
+48
-11
@@ -1,11 +1,53 @@
|
||||
local ns = vim.api.nvim_create_namespace('line_blame');
|
||||
|
||||
local lineBlame = function(input_file_path, input_comma_separated_mail_list, blame_text, blame_highlight, blame_position)
|
||||
local clearBlame = function()
|
||||
vim.api.nvim_buf_clear_namespace(0, ns, 0, -1)
|
||||
end
|
||||
|
||||
local setNvimMark = function(line_number, blame_text, blame_highlight, blame_position)
|
||||
vim.api.nvim_buf_set_extmark(0, ns, line_number, 0, {
|
||||
id = line_number + 1, -- cant be 0
|
||||
virt_text = { { blame_text, blame_highlight } },
|
||||
virt_text_pos = blame_position,
|
||||
priority = 1004,
|
||||
hl_mode = 'combine',
|
||||
})
|
||||
end
|
||||
|
||||
local lineBlame = function(input_file_path, line_number, input_comma_separated_mail_list, blame_text, blame_highlight,
|
||||
blame_position)
|
||||
local git_exit_code = os.execute("git log >/dev/null 2>&1")
|
||||
|
||||
if git_exit_code ~= 0 then
|
||||
return nil
|
||||
end
|
||||
|
||||
local handler = io.popen("git blame -L " .. line_number .. "," .. line_number .. " -e " ..
|
||||
input_file_path .. " | awk '{print $2}'")
|
||||
|
||||
if handler == nil then
|
||||
return nil
|
||||
end
|
||||
|
||||
local result = handler:read("L")
|
||||
|
||||
if result == nil then
|
||||
return nil
|
||||
end
|
||||
|
||||
local mail = string.match(result, "%(<(.+)>")
|
||||
|
||||
if not mail or mail == nil or mail == "" then
|
||||
return nil
|
||||
end
|
||||
|
||||
for target_mail in string.gmatch(input_comma_separated_mail_list, "[^,]+") do
|
||||
if target_mail == mail then
|
||||
setNvimMark(tonumber(line_number), blame_text, blame_highlight, blame_position)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- lineBlame
|
||||
-- does everything the plugin needs xd
|
||||
-- @param blame_highlight: 'Normal'
|
||||
-- @param blame_position: 'eol' | 'overlay' | 'right_align'
|
||||
local fileBlame = function(input_file_path, input_comma_separated_mail_list, blame_text, blame_highlight, blame_position)
|
||||
local handler = io.popen("git blame -e " .. input_file_path .. " | awk '{print $2$6}'")
|
||||
@@ -19,13 +61,7 @@ local fileBlame = function(input_file_path, input_comma_separated_mail_list, bla
|
||||
for current_line_mail, line_number in string.gmatch(result, "%(<(.+)>(%d+)%)") do
|
||||
for target_mail in string.gmatch(input_comma_separated_mail_list, "[^,]+") do
|
||||
if target_mail == current_line_mail then
|
||||
vim.api.nvim_buf_set_extmark(0, ns, tonumber(line_number) - 1, 0, {
|
||||
id = tonumber(line_number),
|
||||
virt_text = { { blame_text, blame_highlight } },
|
||||
virt_text_pos = blame_position,
|
||||
priority = 700,
|
||||
hl_mode = 'combine',
|
||||
})
|
||||
setNvimMark(tonumber(line_number) - 1, blame_text, blame_highlight, blame_position)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -35,6 +71,7 @@ local fileBlame = function(input_file_path, input_comma_separated_mail_list, bla
|
||||
end
|
||||
|
||||
return {
|
||||
clearBlame = clearBlame,
|
||||
lineBlame = lineBlame,
|
||||
fileBlame = fileBlame,
|
||||
}
|
||||
+45
-10
@@ -5,25 +5,60 @@ local defaultBlameTextColor = "#bcb8b1"
|
||||
local defaultBlameText = "- Monkey alert 🐒"
|
||||
local defaultBlamePosition = "eol"
|
||||
|
||||
local function setup(opts)
|
||||
vim.api.nvim_set_hl(0, 'Monkey', { fg = opts.blameTextColorHex or defaultBlameTextColor, bold = false })
|
||||
vim.g.monkeyMailList = opts.monkeyMailList or defaultList
|
||||
vim.g.monkeyBlameText = opts.blameText or defaultBlameText
|
||||
vim.g.monkeyBlamePosition = opts.blamePosition or defaultBlamePosition
|
||||
local function clearBlame()
|
||||
blame.clearBlame()
|
||||
end
|
||||
|
||||
local function blameCurrentFile()
|
||||
blame.fileBlame(vim.api.nvim_buf_get_name(0), vim.g.monkeyMailList, vim.g.monkeyBlameText,
|
||||
"Monkey", vim.g.monkeyBlamePosition)
|
||||
clearBlame()
|
||||
blame.fileBlame(vim.api.nvim_buf_get_name(0), vim.g.monkey_mail_list, vim.g.monkey_blame_text,
|
||||
"Monkey", vim.g.monkey_blame_position)
|
||||
end
|
||||
|
||||
local function blameCurrentLine()
|
||||
blame.lineBlame(vim.api.nvim_buf_get_name(0), vim.g.monkeyMailList, vim.g.monkeyBlameText,
|
||||
"Monkey", vim.g.monkeyBlamePosition)
|
||||
clearBlame()
|
||||
local row = vim.api.nvim_win_get_cursor(0)[1]
|
||||
blame.lineBlame(vim.api.nvim_buf_get_name(0), tonumber(row) - 1, vim.g.monkey_mail_list,
|
||||
vim.g.monkey_blame_text,
|
||||
"Monkey", vim.g.monkey_blame_position)
|
||||
end
|
||||
|
||||
local function updateLineBlame()
|
||||
if vim.bo.buftype == nil or vim.bo.buftype == '' then
|
||||
clearBlame()
|
||||
blameCurrentLine()
|
||||
end
|
||||
end
|
||||
|
||||
local function enableOnLine()
|
||||
-- vim.api.nvim_create_autocmd("BufNew", {
|
||||
-- callback = function(event)
|
||||
-- local status = vim.api.nvim_buf_attach(event.buf, false, { on_changedtick = updateLineBlame })
|
||||
-- -- status == false, for buffers that aren't bound to a file, because the buffer isn't loaded yet
|
||||
-- end
|
||||
-- })
|
||||
vim.api.nvim_create_autocmd("CursorMoved", {
|
||||
callback = function()
|
||||
updateLineBlame()
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
local function setup(opts)
|
||||
vim.api.nvim_set_hl(0, 'Monkey', { fg = opts.blame_text_color_hex or defaultBlameTextColor, bold = false })
|
||||
vim.g.monkey_mail_list = opts.monkey_mail_list or defaultList
|
||||
vim.g.monkey_blame_text = opts.blame_text or defaultBlameText
|
||||
vim.g.monkey_blame_position = opts.blame_position or defaultBlamePosition
|
||||
|
||||
if opts.auto_attach then
|
||||
enableOnLine()
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
setup = setup,
|
||||
blameLine = blameCurrentLine,
|
||||
blameFile = blameCurrentFile
|
||||
blameFile = blameCurrentFile,
|
||||
blameClear = clearBlame,
|
||||
enable = enableOnLine
|
||||
}
|
||||
Reference in new issue
Block a user