From 9bb074739673af2fa35a2f0f30908291f4fb48b9 Mon Sep 17 00:00:00 2001 From: Ray Jameson <67468725+RayJameson@users.noreply.github.com> Date: Fri, 23 Jun 2023 00:06:03 +0600 Subject: [PATCH] feat(harpoon)!: remove "j" keymap, make "t" keymap dynamic based on $TMUX (#292) * fix(harpoon): which key display fix * fix(harpoon): error when user doesn't input terminal number * feat(harpoon)!: remove "j" keymap, make "t" keymap dynamic based on $TMUX * feat(harpoon): add keymap to jump mark index * chore(harpoon): fix typos, simplify variable setting, change formatting Co-authored-by: Micah Halter --------- Co-authored-by: Micah Halter --- lua/astrocommunity/motion/harpoon/init.lua | 35 ++++++++++++++-------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/lua/astrocommunity/motion/harpoon/init.lua b/lua/astrocommunity/motion/harpoon/init.lua index fdc31da77..1eb51704d 100644 --- a/lua/astrocommunity/motion/harpoon/init.lua +++ b/lua/astrocommunity/motion/harpoon/init.lua @@ -1,4 +1,7 @@ local prefix = "" +local running_tmux_session = vim.fn.exists "$TMUX" == 1 +local dynamic_tmux_keymap_desc = "Go to " .. running_tmux_session and "TMUX" or "terminal" .. " window" +local icon = vim.g.icons_enabled and "󱡀 " or "" return { "ThePrimeagen/harpoon", dependencies = { @@ -7,27 +10,35 @@ return { }, cmd = { "Harpoon" }, keys = { - { prefix, desc = "Harpoon" }, + { prefix, function() end, desc = icon .. "Harpoon" }, { prefix .. "a", function() require("harpoon.mark").add_file() end, desc = "Add file" }, { prefix .. "e", function() require("harpoon.ui").toggle_quick_menu() end, desc = "Toggle quick menu" }, - { "", function() require("harpoon.ui").nav_prev() end, desc = "Goto previous mark" }, - { "", function() require("harpoon.ui").nav_next() end, desc = "Goto next mark" }, - { prefix .. "m", "Telescope harpoon marks", desc = "Show marks in Telescope" }, { - prefix .. "t", + "", function() - local num = tonumber(vim.fn.input "GoTo terminal window number: ") - require("harpoon.term").gotoTerminal(num) + local num = tonumber(vim.fn.input "Go to mark index: ") + if num == nil then return end + require("harpoon.ui").nav_file(num) end, - desc = "Goto to terminal window", + desc = "Goto index of mark", }, + { "", function() require("harpoon.ui").nav_prev() end, desc = "Goto previous mark" }, + { "", function() require("harpoon.ui").nav_next() end, desc = "Goto next mark" }, + { prefix .. "m", "Telescope harpoon marks", desc = "Show marks in Telescope" }, { - prefix .. "j", + prefix .. "t", function() - local num = tonumber(vim.fn.input "GoTo Tmux window number: ") - require("harpoon.tmux").gotoTerminal(num) + if running_tmux_session then + local num = tonumber(vim.fn.input "GoTo Tmux window number: ") + if num == nil then return end + require("harpoon.tmux").gotoTerminal(num) + else + local num = tonumber(vim.fn.input "GoTo terminal window number: ") + if num == nil then return end + require("harpoon.term").gotoTerminal(num) + end end, - desc = "Goto to TMUX tmux window", + desc = dynamic_tmux_keymap_desc, }, }, }