aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjakob.stendahl <jakob.stendahl@infomedia.dk>2024-06-19 18:33:33 +0200
committerjakob.stendahl <jakob.stendahl@infomedia.dk>2024-06-19 18:33:33 +0200
commitc664883e31ef5e82785c114cd7a46c812a5c7f3e (patch)
tree2ded15e358261d1bf2eb632bb70c1e5fc690c2bb
parent91adf175d2d6041ac909d9916b16158433b803d9 (diff)
downloaddotfiles-c664883e31ef5e82785c114cd7a46c812a5c7f3e.tar.gz
dotfiles-c664883e31ef5e82785c114cd7a46c812a5c7f3e.zip
Complete branches
-rwxr-xr-xCommon/nvim/lua/helper_functions.lua23
1 files changed, 22 insertions, 1 deletions
diff --git a/Common/nvim/lua/helper_functions.lua b/Common/nvim/lua/helper_functions.lua
index 3067fd7..9d5a80e 100755
--- a/Common/nvim/lua/helper_functions.lua
+++ b/Common/nvim/lua/helper_functions.lua
@@ -158,7 +158,28 @@ function GRevisionDiff(args)
end
vim.cmd("copen")
end
-vim.api.nvim_create_user_command('GRevisionDiff', GRevisionDiff, {nargs = "?", desc = 'Show diff of current branch with the specified branch (default: master)'})
+
+function get_git_branches()
+ local handle = io.popen("git branch --list --format='%(refname:short)'")
+ local result = handle:read("*a")
+ handle:close()
+
+ local branches = {}
+ for branch in result:gmatch("[^\r\n]+") do
+ table.insert(branches, branch)
+ end
+ return branches
+end
+
+function complete_git_branches(arg_lead, cmd_line, cursor_pos)
+ return get_git_branches()
+end
+
+vim.api.nvim_create_user_command('GRevisionDiff', GRevisionDiff, {
+ nargs = "?",
+ desc = 'Show diff of current branch with the specified branch (default: master)',
+ complete = complete_git_branches
+})
function close_existing_diff_windows()
local windows = vim.api.nvim_list_wins()