From 242577f9d047faa349d4bad96e51053ab041c922 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Tue, 26 Nov 2024 10:52:31 +0100 Subject: [PATCH] overwrite default stash selection without index flag --- lua/kickstart/plugins/telescope.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lua/kickstart/plugins/telescope.lua b/lua/kickstart/plugins/telescope.lua index a2f8a21..316c7c5 100644 --- a/lua/kickstart/plugins/telescope.lua +++ b/lua/kickstart/plugins/telescope.lua @@ -204,6 +204,31 @@ return { local utils = require 'telescope.utils' local action_state = require 'telescope.actions.state' + -- Reference: https://github.com/nvim-telescope/telescope.nvim/blob/master/lua/telescope/actions/init.lua#L587 + local function git_apply_stash(prompt_bufnr) + local selection = action_state.get_selected_entry() + if selection == nil then + utils.__warn_no_selection 'actions.git_apply_stash' + return + end + actions.close(prompt_bufnr) + -- Remove unwanted '--index' flag from command + local _, ret, stderr = utils.get_os_command_output { 'git', 'stash', 'apply', selection.value } + if ret == 0 then + utils.notify('actions.git_apply_stash', { + msg = string.format("applied: '%s' ", selection.value), + level = 'INFO', + }) + else + utils.notify('actions.git_apply_stash', { + ---@diagnostic disable-next-line: param-type-mismatch + msg = string.format("Error when applying: %s. Git returned: '%s'", selection.value, table.concat(stderr, ' ')), + level = 'ERROR', + }) + end + end + actions.select_default:replace(git_apply_stash) + -- custom function to match stash index inside curly brackets local function match_bracket(str, arr) string.gsub(str, '{(.-)}', function(match)