From 280500ef036ca62724b60afecc914b082d324ef0 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Thu, 20 Feb 2025 17:51:22 +0100 Subject: [PATCH] Add c-v & c-s mapping for commit pickers --- nvim/lua/plugins/telescope.lua | 10 ++++++++++ nvim/lua/telescope/_extensions/git_show.lua | 18 ++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/nvim/lua/plugins/telescope.lua b/nvim/lua/plugins/telescope.lua index c6f8ce3..6857338 100644 --- a/nvim/lua/plugins/telescope.lua +++ b/nvim/lua/plugins/telescope.lua @@ -105,6 +105,16 @@ return { [""] = git_show, [""] = git_show_split, [""] = git_fixup, + [""] = function(bufr) + actions.close(bufr) + local entry = action_state.get_selected_entry() + vim.cmd("Gvsplit " .. entry.value .. ":" .. entry.current_file) + end, + [""] = function(bufr) + actions.close(bufr) + local entry = action_state.get_selected_entry() + vim.cmd("Gsplit " .. entry.value .. ":" .. entry.current_file) + end, }, }, }, diff --git a/nvim/lua/telescope/_extensions/git_show.lua b/nvim/lua/telescope/_extensions/git_show.lua index 7016cd8..71b6a8a 100644 --- a/nvim/lua/telescope/_extensions/git_show.lua +++ b/nvim/lua/telescope/_extensions/git_show.lua @@ -9,7 +9,7 @@ local conf = require("telescope.config").values local actions = require "telescope.actions" local action_state = require "telescope.actions.state" -local function map(t, f) +local function tmap(t, f) local t1 = {} for i = 1, #t do t1[i] = f(t[i]) @@ -57,10 +57,10 @@ local git_show = function(opts) local gen_new_finder = function() local git_cmd = { "git", "show", "--name-status", '--pretty=tformat:', opts.ref } - local output = utils.get_os_command_output(git_cmd, opts.cwd) + local output = utils.get_os_command_output(git_cmd, opts.cwd) -- We convert {StatusInOneChar}\t{Path} to {StatusInOneChar}{NoStatusInOneChar} {Path} where NoStatusInOneChar is a space. -- This is to conform to git status --porcelaine=v1 - output = map(output, function(x) return string.gsub(x, "\t", " ", 1) end) + output = tmap(output, function(x) return string.gsub(x, "\t", " ", 1) end) return finders.new_table { results = output, @@ -78,12 +78,22 @@ local git_show = function(opts) prompt_title = "Git show " .. opts.ref, finder = initial_finder, previewer = git_file_show(opts), - attach_mappings = function(prompt_bufnr, _) + attach_mappings = function(prompt_bufnr, map) actions.select_default:replace(function() actions.close(prompt_bufnr) local selection = action_state.get_selected_entry() vim.cmd("Gedit " .. opts.ref .. ":" .. selection.value) end) + map({ "i", "n" }, "", function(bufr) + actions.close(bufr) + local entry = action_state.get_selected_entry() + vim.cmd("Gvsplit " .. entry.value .. ":" .. entry.current_file) + end) + map({ "i", "n" }, "", function(bufr) + actions.close(bufr) + local entry = action_state.get_selected_entry() + vim.cmd("Gsplit " .. entry.value .. ":" .. entry.current_file) + end) return true end, })