This commit is contained in:
Alex Yatskov 2023-09-22 14:56:23 -07:00
parent 48b42f0cb1
commit 7cb2603262

View File

@ -1,35 +1,39 @@
-- UnAlign -- UnAlign
vim.api.nvim_create_user_command( vim.api.nvim_create_user_command(
'UnAlign', 'UnAlign',
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 -- GitStreak
local function git_streak() vim.api.nvim_create_user_command(
local function call(args) 'GitStreak',
output = vim.fn.system(table.concat(args, ' ')) function(ctx)
return string.gsub(output, '%s+$', '') local function call(args)
end output = vim.fn.system(table.concat(args, ' '))
return string.gsub(output, '%s+$', '')
end
local root_dir = call({'git', 'rev-parse', '--show-toplevel'}) local root_dir = call({'git', 'rev-parse', '--show-toplevel'})
local author = call({'git', 'config', 'user.name'}) local author = call({'git', 'config', 'user.name'})
local hash = call{'git', 'log', '-n1', '--author="^((?!' .. author .. ').)*$"', '--perl-regexp', '--pretty=format:"%H"'} local hash = call{'git', 'log', '-n1', '--author="^((?!' .. author .. ').)*$"', '--perl-regexp', '--pretty=format:"%H"'}
if #hash == 0 then if #hash == 0 then
print('All commits are by current author') print('All commits are by current author')
return return
end end
local names = call({'git', 'diff', '--name-only', hash}) local names = call({'git', 'diff', '--name-only', hash})
if #names == 0 then if #names == 0 then
print('No files changed since previous author') print('No files changed since previous author')
return return
end end
for name in string.gmatch(names, '[^\r\n]+') do for name in string.gmatch(names, '[^\r\n]+') do
vim.cmd(string.format('e %s/%s', root_dir, name)) vim.cmd(string.format('e %s/%s', root_dir, name))
end end
end end,
{}
vim.api.nvim_create_user_command('GitStreak', git_streak, {nargs = 0}) )