Compare commits
11 Commits
7925cdd229
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 2add9d2a8c | |||
| 213a39f816 | |||
| 52cb2c9046 | |||
| 30a44756ff | |||
| 3015299545 | |||
|
|
ffe3dd73ff | ||
| 084d0f21cd | |||
| 3b005ab8b4 | |||
| 182c6615ab | |||
| 2c03780bf5 | |||
| ffd3fb62f6 |
47
README.md
47
README.md
@@ -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!
|
||||
|
||||

|
||||
|
||||
@@ -1,9 +1,55 @@
|
||||
local ns = vim.api.nvim_create_namespace('line_blame');
|
||||
-- lineBlame
|
||||
-- - does everything the plugin needs xd
|
||||
-- @param blame_highlight: 'Normal'
|
||||
|
||||
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
|
||||
|
||||
-- @param blame_position: 'eol' | 'overlay' | 'right_align'
|
||||
local lineBlame = function(input_file_path, input_comma_separated_mail_list, blame_text, blame_highlight, blame_position)
|
||||
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}'")
|
||||
|
||||
if handler == nil then
|
||||
@@ -15,25 +61,17 @@ local lineBlame = 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
|
||||
local extid = vim.api.nvim_buf_set_extmark(0, ns, tonumber(line_number), 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
|
||||
|
||||
-- ,virt_text = {[ "test", "WildMenu"]}
|
||||
end
|
||||
result = handler:read("L")
|
||||
end
|
||||
handler:close()
|
||||
end
|
||||
|
||||
-- lineBlame("./README.md")
|
||||
|
||||
return {
|
||||
clearBlame = clearBlame,
|
||||
lineBlame = lineBlame,
|
||||
fileBlame = fileBlame,
|
||||
}
|
||||
|
||||
@@ -1,24 +1,64 @@
|
||||
local blame = require("./line-blame")
|
||||
|
||||
local defaultList = "one;two"
|
||||
-- vim.g.monkeyUserList = defaultList
|
||||
vim.g.monkeyMailList = defaultList
|
||||
local defaultList = "one,two"
|
||||
local defaultBlameTextColor = "#bcb8b1"
|
||||
local defaultBlameText = "- Monkey alert 🐒"
|
||||
local defaultBlamePosition = "eol"
|
||||
|
||||
local function setup(opts)
|
||||
vim.g.monkeyMailList = opts.monkeyMailList
|
||||
-- vim.g.monkeyUserList = opts.monkeyUserList
|
||||
local function clearBlame()
|
||||
blame.clearBlame()
|
||||
end
|
||||
|
||||
local function blameCurrentFile()
|
||||
blame.lineBlame(vim.api.nvim_buf_get_name(0), "test,another,dani.heras@hotmail.com,final", "| Found a fkin monkey 🐒",
|
||||
"Normal", "eol")
|
||||
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()
|
||||
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,
|
||||
blame = blameCurrentFile
|
||||
blameLine = blameCurrentLine,
|
||||
blameFile = blameCurrentFile,
|
||||
blameClear = clearBlame,
|
||||
enable = enableOnLine
|
||||
}
|
||||
|
||||
-- NOTE:
|
||||
-- vim.log.levels.DEBUG vim.log.levels.ERROR vim.log.levels.INFO vim.log.levels.TRACE vim.log.levels.WARN vim.log.levels.OFF
|
||||
--
|
||||
|
||||
Reference in New Issue
Block a user