Update scripts

This commit is contained in:
Alex Yatskov 2024-03-27 12:00:52 -07:00
parent 20a34c5699
commit 1aacc80e6e

View File

@ -5,6 +5,10 @@ end
local function get_branch_parent() local function get_branch_parent()
local author = invoke({'git', 'config', 'user.name'}) local author = invoke({'git', 'config', 'user.name'})
if #author == 0 then
print('User name is not set')
return
end
local hash = invoke{ local hash = invoke{
'git', 'git',
@ -22,6 +26,13 @@ local function get_branch_parent()
end end
end end
local function edit_git_paths(names)
local root_dir = invoke({'git', 'rev-parse', '--show-toplevel'})
for name in string.gmatch(names, '[^\r\n]+') do
vim.cmd(string.format('e %s/%s', root_dir, name))
end
end
-- UnAlign -- UnAlign
vim.api.nvim_create_user_command( vim.api.nvim_create_user_command(
'UnAlign', 'UnAlign',
@ -31,21 +42,22 @@ vim.api.nvim_create_user_command(
{range = '%'} {range = '%'}
) )
-- Conflicts
vim.api.nvim_create_user_command(
'Conflicts',
function(ctx)
edit_git_paths(invoke({'git', 'diff', '--name-only', '--diff-filter=U'}))
end,
{}
)
-- TopicEdit -- TopicEdit
vim.api.nvim_create_user_command( vim.api.nvim_create_user_command(
'TopicEdit', 'TopicEdit',
function(ctx) function(ctx)
local hash = get_branch_parent() local hash = get_branch_parent()
if hash then if hash then
local names = invoke({'git', 'diff', '--name-only', hash}) edit_git_paths(invoke({'git', 'diff', '--name-only', hash}))
if #names == 0 then
print('No files changed since previous author')
else
local root_dir = invoke({'git', 'rev-parse', '--show-toplevel'})
for name in string.gmatch(names, '[^\r\n]+') do
vim.cmd(string.format('e %s/%s', root_dir, name))
end
end
end end
end, end,
{} {}