From ca92ec1a830a61a0b88fff925f2146ab46e0f7c9 Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Sat, 27 Feb 2021 16:26:25 +0100 Subject: fix: a lot of small things and adds more customization for caret (#554) Attention: prompt_prefix will no longer add a space at the end. So if you still want a space at the end make sure your configuration has one. The default should not be changed. So if you haven't copied prompt_prefix in your config this doesn't affect you. Feat: - prompt prefix does no longer always end with space - selection_caret configurable. Default: `> ` - result_prefix configurable. Default: ` ` - more actions for git_branches - does track the branch - does rebase branch - also added delete branch action but not configured. See readme on how to do that Fixes: - fix docgen ci - Better error for lsp_workspace_symbols - better formatting for CONTRIBUTING.md - move from systemlist to plenary.job - git branch now supports checkout on remote branches --- lua/telescope/actions/init.lua | 67 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) (limited to 'lua/telescope/actions/init.lua') diff --git a/lua/telescope/actions/init.lua b/lua/telescope/actions/init.lua index bf6bd4f..2fa7ce2 100644 --- a/lua/telescope/actions/init.lua +++ b/lua/telescope/actions/init.lua @@ -264,7 +264,72 @@ actions.git_checkout = function(prompt_bufnr) local cwd = action_state.get_current_picker(prompt_bufnr).cwd local selection = action_state.get_selected_entry() actions.close(prompt_bufnr) - utils.get_os_command_output({ 'git', 'checkout', selection.value }, cwd) + local _, ret, stderr = utils.get_os_command_output({ 'git', 'checkout', selection.value }, cwd) + if ret == 0 then + print("Checked out: " .. selection.value) + else + print(string.format( + 'Error when checking out: %s. Git returned: "%s"', + selection.value, + table.concat(stderr, ' ') + )) + end +end + +actions.git_track_branch = function(prompt_bufnr) + local cwd = action_state.get_current_picker(prompt_bufnr).cwd + local selection = action_state.get_selected_entry() + actions.close(prompt_bufnr) + local _, ret, stderr = utils.get_os_command_output({ 'git', 'checkout', '--track', selection.value }, cwd) + if ret == 0 then + print("Tracking branch: " .. selection.value) + else + print(string.format( + 'Error when tracking branch: %s. Git returned: "%s"', + selection.value, + table.concat(stderr, ' ') + )) + end +end + +actions.git_delete_branch = function(prompt_bufnr) + local cwd = action_state.get_current_picker(prompt_bufnr).cwd + local selection = action_state.get_selected_entry() + + local confirmation = vim.fn.input('Do you really wanna delete branch ' .. selection.value .. '? [Y/n] ') + if confirmation ~= '' and string.lower(confirmation) ~= 'y' then return end + + actions.close(prompt_bufnr) + local _, ret, stderr = utils.get_os_command_output({ 'git', 'branch', '-D', selection.value }, cwd) + if ret == 0 then + print("Deleted branch: " .. selection.value) + else + print(string.format( + 'Error when deleting branch: %s. Git returned: "%s"', + selection.value, + table.concat(stderr, ' ') + )) + end +end + +actions.git_rebase_branch = function(prompt_bufnr) + local cwd = action_state.get_current_picker(prompt_bufnr).cwd + local selection = action_state.get_selected_entry() + + local confirmation = vim.fn.input('Do you really wanna delete branch ' .. selection.value .. '? [Y/n] ') + if confirmation ~= '' and string.lower(confirmation) ~= 'y' then return end + + actions.close(prompt_bufnr) + local _, ret, stderr = utils.get_os_command_output({ 'git', 'rebase', selection.value }, cwd) + if ret == 0 then + print("Rebased branch: " .. selection.value) + else + print(string.format( + 'Error when rebasing branch: %s. Git returned: "%s"', + selection.value, + table.concat(stderr, ' ') + )) + end end actions.git_staging_toggle = function(prompt_bufnr) -- cgit v1.2.3