Skip to content

Commit

Permalink
Git message view
Browse files Browse the repository at this point in the history
  • Loading branch information
Conni2461 committed Feb 26, 2021
1 parent 872b1eb commit f161aa6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lua/telescope/builtin/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ git.commits = function(opts)
alt_previewers = {
previewers.git_commit_diff_to_head.new(opts),
previewers.git_commit_diff_as_was.new(opts),
previewers.git_commit_message.new(opts),
},
sorter = conf.file_sorter(opts),
attach_mappings = function()
Expand All @@ -74,6 +75,7 @@ git.bcommits = function(opts)
alt_previewers = {
previewers.git_commit_diff_to_head.new(opts),
previewers.git_commit_diff_as_was.new(opts),
previewers.git_commit_message.new(opts),
},
sorter = conf.file_sorter(opts),
attach_mappings = function()
Expand Down
33 changes: 33 additions & 0 deletions lua/telescope/previewers/buffer_previewer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,39 @@ previewers.git_commit_diff_as_was = defaulter(function(opts)
}
end, {})

previewers.git_commit_message = defaulter(function(opts)
local hl_map = {
'TelescopeResultsIdentifier',
'TelescopePreviewUser',
'TelescopePreviewDate'
}
return previewers.new_buffer_previewer {
title = "Git Message",
get_buffer_by_name = function(_, entry)
return entry.value
end,

define_preview = function(self, entry, status)
local cmd = { 'git', '--no-pager', 'log', '-n 1', entry.value }

putils.job_maker(cmd, self.state.bufnr, {
value = entry.value,
bufname = self.state.bufname,
cwd = opts.cwd,
callback = function(bufnr, content)
if not content then return end
for k, v in ipairs(hl_map) do
local _, s = content[k]:find('%s')
if s then
vim.api.nvim_buf_add_highlight(bufnr, ns_previewer, v, k - 1, s, #content[k])
end
end
end
})
end
}
end, {})

previewers.git_file_diff = defaulter(function(opts)
return previewers.new_buffer_previewer {
title = "Git File Diff Preview",
Expand Down
1 change: 1 addition & 0 deletions lua/telescope/previewers/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ previewers.git_commit_diff = buffer_previewer.git_commit_diff
previewers.git_commit_diff_to_parent = buffer_previewer.git_commit_diff_to_parent
previewers.git_commit_diff_to_head = buffer_previewer.git_commit_diff_to_head
previewers.git_commit_diff_as_was = buffer_previewer.git_commit_diff_as_was
previewers.git_commit_message = buffer_previewer.git_commit_message
previewers.git_file_diff = buffer_previewer.git_file_diff
previewers.ctags = buffer_previewer.ctags
previewers.builtin = buffer_previewer.builtin
Expand Down

0 comments on commit f161aa6

Please sign in to comment.