Add GitStreak

This commit is contained in:
Alex Yatskov 2023-09-22 14:30:42 -07:00
parent ba35120c4e
commit 1f513ae9b9

View File

@ -4,3 +4,38 @@ vim.api.nvim_create_user_command(
function(ctx) vim.cmd(ctx.line1 .. ',' .. ctx.line2 .. 's/\\(\\S\\+\\)\\s\\{2,\\}/\\1 /g') end, function(ctx) vim.cmd(ctx.line1 .. ',' .. ctx.line2 .. 's/\\(\\S\\+\\)\\s\\{2,\\}/\\1 /g') end,
{range = '%'} {range = '%'}
) )
-- GitStreak
local function git_streak()
local root_dir = vim.fn.system(table.concat({'git', 'rev-parse', '--show-toplevel'}, ' '))
root_dir = string.gsub(root_dir, '%s+$', '')
if #root_dir == 0 then
return
end
local author = vim.fn.system(table.concat({'git', 'config', 'user.name'}, ' '))
author = string.gsub(author, '%s+$', '')
local hash = vim.fn.system(table.concat({
'git',
'log',
'-n1',
string.format('--author="^((?!%s).)*$"', author),
'--perl-regexp',
'--pretty=format:"%H"'}, ' '))
if #hash == 0 then
return
end
local names = vim.fn.system(table.concat({'git', 'diff', '--name-only', hash}, ' '))
if #names == 0 then
return
end
for name in string.gmatch(names, '[^\r\n]+') do
local path = string.format('%s/%s', root_dir, name)
vim.cmd(string.format('e %s', path))
end
end
vim.api.nvim_create_user_command('GitStreak', git_streak, {nargs = 0})