dotvim/lua/config/util.lua

36 lines
1.0 KiB
Lua
Raw Normal View History

2022-10-22 05:45:38 +00:00
-- UnAlign
vim.api.nvim_create_user_command(
'UnAlign',
function(ctx) vim.cmd(ctx.line1 .. ',' .. ctx.line2 .. 's/\\(\\S\\+\\)\\s\\{2,\\}/\\1 /g') end,
2022-10-22 16:53:29 +00:00
{range = '%'}
2022-10-22 05:45:38 +00:00
)
2023-09-22 21:30:42 +00:00
-- GitStreak
local function git_streak()
2023-09-22 21:39:09 +00:00
local function call(args)
output = vim.fn.system(table.concat(args, ' '))
return string.gsub(output, '%s+$', '')
end
local root_dir = call({'git', 'rev-parse', '--show-toplevel'})
local author = call({'git', 'config', 'user.name'})
2023-09-22 21:30:42 +00:00
2023-09-22 21:39:09 +00:00
local hash = call{'git', 'log', '-n1', '--author="^((?!' .. author .. ').)*$"', '--perl-regexp', '--pretty=format:"%H"'}
2023-09-22 21:30:42 +00:00
if #hash == 0 then
2023-09-22 21:47:38 +00:00
print('All commits are by current author')
2023-09-22 21:30:42 +00:00
return
end
2023-09-22 21:39:09 +00:00
local names = call({'git', 'diff', '--name-only', hash})
2023-09-22 21:30:42 +00:00
if #names == 0 then
2023-09-22 21:47:38 +00:00
print('No files changed since previous author')
2023-09-22 21:30:42 +00:00
return
end
for name in string.gmatch(names, '[^\r\n]+') do
2023-09-22 21:39:09 +00:00
vim.cmd(string.format('e %s/%s', root_dir, name))
2023-09-22 21:30:42 +00:00
end
end
vim.api.nvim_create_user_command('GitStreak', git_streak, {nargs = 0})