From 7cb26032629c0bcbf31bf8eb8308e18c05fa017e Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Fri, 22 Sep 2023 14:56:23 -0700 Subject: [PATCH] Cleanup --- lua/config/util.lua | 52 ++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/lua/config/util.lua b/lua/config/util.lua index 423ffad..bd0d748 100644 --- a/lua/config/util.lua +++ b/lua/config/util.lua @@ -1,35 +1,39 @@ -- UnAlign vim.api.nvim_create_user_command( '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 = '%'} ) -- GitStreak -local function git_streak() - local function call(args) - output = vim.fn.system(table.concat(args, ' ')) - return string.gsub(output, '%s+$', '') - end +vim.api.nvim_create_user_command( + 'GitStreak', + function(ctx) + 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'}) + local root_dir = call({'git', 'rev-parse', '--show-toplevel'}) + local author = call({'git', 'config', 'user.name'}) - local hash = call{'git', 'log', '-n1', '--author="^((?!' .. author .. ').)*$"', '--perl-regexp', '--pretty=format:"%H"'} - if #hash == 0 then - print('All commits are by current author') - return - end + local hash = call{'git', 'log', '-n1', '--author="^((?!' .. author .. ').)*$"', '--perl-regexp', '--pretty=format:"%H"'} + if #hash == 0 then + print('All commits are by current author') + return + end - local names = call({'git', 'diff', '--name-only', hash}) - if #names == 0 then - print('No files changed since previous author') - return - end + local names = call({'git', 'diff', '--name-only', hash}) + if #names == 0 then + print('No files changed since previous author') + return + end - for name in string.gmatch(names, '[^\r\n]+') do - vim.cmd(string.format('e %s/%s', root_dir, name)) - end -end - -vim.api.nvim_create_user_command('GitStreak', git_streak, {nargs = 0}) + for name in string.gmatch(names, '[^\r\n]+') do + vim.cmd(string.format('e %s/%s', root_dir, name)) + end + end, + {} +)