Add lock deletion

This commit is contained in:
Alex Yatskov 2024-10-03 21:51:30 -07:00
parent e1c45dfcce
commit 5abed9dd38

View File

@ -1,27 +1,3 @@
-- UnAlign
vim.api.nvim_create_user_command(
'UnAlign',
function(ctx)
vim.cmd(ctx.line1 .. ',' .. ctx.line2 .. 's/\\(\\S\\+\\)\\s\\{2,\\}/\\1 /g')
end,
{range = '%'}
)
-- BuffDeleteAllButCurrent
vim.api.nvim_create_user_command(
'BuffDeleteAllButCurrent',
function()
local bufs = vim.api.nvim_list_bufs()
local current_buf = vim.api.nvim_get_current_buf()
for _, i in ipairs(bufs) do
if i ~= current_buf then
vim.api.nvim_buf_delete(i, {})
end
end
end,
{}
)
local function invoke(args)
local output = vim.fn.system(table.concat(args, ' '))
return string.gsub(output, '%s+$', '')
@ -61,6 +37,12 @@ local function git_edit_paths(names)
end
end
local function git_delete_lock()
local root = invoke({'git', 'rev-parse', '--show-toplevel'})
local lock_path = root .. '/.git/index.lock'
vim.fn.delete(lock_path)
end
-- GitTopicEdit
vim.api.nvim_create_user_command(
'GitTopicEdit',
@ -84,3 +66,34 @@ vim.api.nvim_create_user_command(
end,
{nargs = '?'}
)
-- GitUnlock
vim.api.nvim_create_user_command(
'GitUnlock',
git_delete_lock,
{}
)
-- UnAlign
vim.api.nvim_create_user_command(
'UnAlign',
function(ctx)
vim.cmd(ctx.line1 .. ',' .. ctx.line2 .. 's/\\(\\S\\+\\)\\s\\{2,\\}/\\1 /g')
end,
{range = '%'}
)
-- BuffDeleteAllButCurrent
vim.api.nvim_create_user_command(
'BuffDeleteAllButCurrent',
function()
local bufs = vim.api.nvim_list_bufs()
local current_buf = vim.api.nvim_get_current_buf()
for _, i in ipairs(bufs) do
if i ~= current_buf then
vim.api.nvim_buf_delete(i, {})
end
end
end,
{}
)