Skip to content

Commit

Permalink
refactor: add option to disable modified sign
Browse files Browse the repository at this point in the history
As requested in #25
  • Loading branch information
hougesen committed Feb 13, 2024
1 parent 719cf09 commit 7a84433
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A lean git blame plugin for neovim.

## Usage

blame-me.nvim _should_ work out of the box. Simply install the using your package manager of choice:
blame-me.nvim _should_ work out of the box. Simply install it using your package manager of choice:

### Lazy

Expand All @@ -19,7 +19,7 @@ local blame_me_plugin = {
}
```

## Available optionsDescription
## Available options

| Name | Default | Description |
| ---------- | ----------------------------------- | -------------------------------------------------------------- |
Expand All @@ -28,3 +28,4 @@ local blame_me_plugin = {
| show_on | `{ 'CursorHold', 'CursorHoldI' }` | List of events to show line information on |
| hide_on | `{ 'CursorMoved', 'CursorMovedI' }` | List of events to hide line information on |
| refresh_on | `{ 'BufEnter', 'BufWritePost' }` | List of events to fresh commit information on |
| signs | `true` | Whether to set `M` sign |
1 change: 1 addition & 0 deletions lua/blame-me/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ M.defaults = {
'BufWritePost',
'BufEnter',
},
signs = true,
}

---@param options unknown
Expand Down
25 changes: 14 additions & 11 deletions lua/blame-me/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ end
---get git blame of file
---@param path string
---@param ns_id integer
---@param set_signs boolean
---@return table<string, string>|nil
function M.get_git_blame(path, ns_id)
function M.get_git_blame(path, ns_id, set_signs)
if path == nil or string.len(path) == 0 then
return nil
end
Expand Down Expand Up @@ -111,16 +112,18 @@ function M.get_git_blame(path, ns_id)

line_commit_map[i] = commit_hash

if M.is_modified_line(commit_hash) then
-- TODO: handle error cases
pcall(function()
editor.set_modified_sign(ns_id, i)
end)
else
-- TODO: handle error cases
pcall(function()
editor.remove_modified_sign(ns_id, i)
end)
if set_signs == true then
if M.is_modified_line(commit_hash) then
-- TODO: handle error cases
pcall(function()
editor.set_modified_sign(ns_id, i)
end)
else
-- TODO: handle error cases
pcall(function()
editor.remove_modified_sign(ns_id, i)
end)
end
end
end

Expand Down
4 changes: 3 additions & 1 deletion lua/blame-me/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ local function refresh_file_git_blame(current_file)
return
end

files[current_file] = git.get_git_blame(current_file, ns_id)
files[current_file] = git.get_git_blame(current_file, ns_id, M.conf.signs)
end

---get commit info of line
Expand Down Expand Up @@ -147,6 +147,8 @@ end
function M.setup(opts)
local conf = require('blame-me.config').set(opts or {})

M.conf = conf

local group = vim.api.nvim_create_augroup('blame_me', { clear = true })

local hide_opts = {
Expand Down

0 comments on commit 7a84433

Please sign in to comment.