From 5abed9dd38a33c2b9f7939fed91be9c57ba4be6f Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Thu, 3 Oct 2024 21:51:30 -0700 Subject: [PATCH] Add lock deletion --- lua/config/util.lua | 61 +++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/lua/config/util.lua b/lua/config/util.lua index 918e3a6..dfbf8e3 100644 --- a/lua/config/util.lua +++ b/lua/config/util.lua @@ -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, + {} +)