picker(git_branch): show committer, upstream and date (#695)
* wip: rich finder for branches for: https://github.com/nvim-telescope/telescope.nvim/issues/569 * fix some diagnostics
This commit is contained in:
@@ -401,7 +401,11 @@ files.tags = function(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
files.current_buffer_tags = function(opts)
|
files.current_buffer_tags = function(opts)
|
||||||
return files.tags(vim.tbl_extend("force", {prompt_title = 'Current Buffer Tags', only_current_file = true, hide_filename = true}, opts))
|
return files.tags(vim.tbl_extend("force", {
|
||||||
|
prompt_title = 'Current Buffer Tags',
|
||||||
|
only_current_file = true,
|
||||||
|
hide_filename = true,
|
||||||
|
}, opts))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function apply_checks(mod)
|
local function apply_checks(mod)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ local make_entry = require('telescope.make_entry')
|
|||||||
local pickers = require('telescope.pickers')
|
local pickers = require('telescope.pickers')
|
||||||
local previewers = require('telescope.previewers')
|
local previewers = require('telescope.previewers')
|
||||||
local utils = require('telescope.utils')
|
local utils = require('telescope.utils')
|
||||||
|
local entry_display = require('telescope.pickers.entry_display')
|
||||||
|
|
||||||
local conf = require('telescope.config').values
|
local conf = require('telescope.config').values
|
||||||
|
|
||||||
@@ -77,17 +78,70 @@ git.bcommits = function(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
git.branches = function(opts)
|
git.branches = function(opts)
|
||||||
local output = utils.get_os_command_output({ 'git', 'branch', '--all' }, opts.cwd)
|
local format = '{'
|
||||||
|
.. '"head":%(if:equals=*)%(HEAD)%(then)true%(else)false%(end)'
|
||||||
|
.. ',"refname":"%(refname)"'
|
||||||
|
.. ',"authorname":"%(authorname)"'
|
||||||
|
.. '%(if)%(upstream)%(then)'
|
||||||
|
.. ',"upstream":"%(upstream:lstrip=2)"'
|
||||||
|
.. '%(else)'
|
||||||
|
.. ',"upstream":""'
|
||||||
|
.. '%(end)'
|
||||||
|
.. ',"committerdate":"%(committerdate:format-local:%Y/%m/%d %H:%M:%S)"'
|
||||||
|
.. '}'
|
||||||
|
local output = utils.get_os_command_output({ 'git', 'for-each-ref', '--format', format }, opts.cwd)
|
||||||
|
|
||||||
local results = {}
|
local results = {}
|
||||||
|
local widths = {
|
||||||
|
name = 0,
|
||||||
|
authorname = 0,
|
||||||
|
upstream = 0,
|
||||||
|
committerdate = 0,
|
||||||
|
}
|
||||||
|
local register_entry = function(entry, trim_refname_prefix)
|
||||||
|
entry.name = string.sub(entry.refname, string.len(trim_refname_prefix)+1)
|
||||||
|
for key, value in pairs(widths) do
|
||||||
|
widths[key] = math.max(value, vim.fn.strdisplaywidth(entry[key]))
|
||||||
|
end
|
||||||
|
if string.len(entry.upstream) > 0 then
|
||||||
|
widths.upstream_indicator = 2
|
||||||
|
end
|
||||||
|
table.insert(results, entry)
|
||||||
|
end
|
||||||
for _, v in ipairs(output) do
|
for _, v in ipairs(output) do
|
||||||
if not string.match(v, 'HEAD') and v ~= '' then
|
local entry = vim.fn.json_decode(v)
|
||||||
if vim.startswith(v, '*') then
|
if entry.head then
|
||||||
table.insert(results, 1, v)
|
goto continue
|
||||||
else
|
elseif vim.startswith(entry.refname, 'refs/remotes/') then
|
||||||
table.insert(results, v)
|
register_entry(entry, 'refs/remotes/')
|
||||||
|
elseif vim.startswith(entry.refname, 'refs/heads/') then
|
||||||
|
register_entry(entry, 'refs/heads/')
|
||||||
end
|
end
|
||||||
|
::continue::
|
||||||
end
|
end
|
||||||
|
if #results == 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local displayer = entry_display.create {
|
||||||
|
separator = " ",
|
||||||
|
items = {
|
||||||
|
{ width = widths.name },
|
||||||
|
{ width = widths.authorname },
|
||||||
|
{ width = widths.upstream_indicator },
|
||||||
|
{ width = widths.upstream },
|
||||||
|
{ width = widths.committerdate },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
local make_display = function(entry)
|
||||||
|
return displayer {
|
||||||
|
{entry.name, 'TelescopeResultsIdentifier'},
|
||||||
|
{entry.authorname},
|
||||||
|
{string.len(entry.upstream) > 0 and '=>' or ''},
|
||||||
|
{entry.upstream, 'TelescopeResultsIdentifier'},
|
||||||
|
{entry.committerdate}
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
pickers.new(opts, {
|
pickers.new(opts, {
|
||||||
@@ -95,14 +149,10 @@ git.branches = function(opts)
|
|||||||
finder = finders.new_table {
|
finder = finders.new_table {
|
||||||
results = results,
|
results = results,
|
||||||
entry_maker = function(entry)
|
entry_maker = function(entry)
|
||||||
local addition = vim.startswith(entry, '*') and '* ' or ' '
|
entry.value = entry.name
|
||||||
entry = entry:gsub('[* ] ', '')
|
entry.ordinal = entry.name
|
||||||
entry = entry:gsub('^remotes/', '')
|
entry.display = make_display
|
||||||
return {
|
return entry
|
||||||
value = entry,
|
|
||||||
ordinal = addition .. entry,
|
|
||||||
display = addition .. entry
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
previewer = previewers.git_branch_log.new(opts),
|
previewer = previewers.git_branch_log.new(opts),
|
||||||
|
|||||||
Reference in New Issue
Block a user