Skip to content

Commit

Permalink
feat(harpoon): make terminal keymaps dynamic based on $TMUX
Browse files Browse the repository at this point in the history
  • Loading branch information
RayJameson committed Jun 20, 2023
1 parent 09113da commit f1a4ca7
Showing 1 changed file with 51 additions and 14 deletions.
65 changes: 51 additions & 14 deletions lua/astrocommunity/motion/harpoon/harpoon.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
local prefix = "<leader><leader>"
local dynamic_tmux_keymap_desc
local running_tmux_seesion = vim.fn.exists "$TMUX" == 1
if running_tmux_seesion then
dynamic_tmux_keymap_desc = "Goto to TMUX window"
else
dynamic_tmux_keymap_desc = "Goto to terminal window"
end
return {
"ThePrimeagen/harpoon",
dependencies = {
Expand All @@ -7,27 +14,57 @@ return {
},
cmd = { "Harpoon" },
keys = {
{ prefix, desc = "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" },
{ "<C-p>", function() require("harpoon.ui").nav_prev() end, desc = "Goto previous mark" },
{ "<C-n>", function() require("harpoon.ui").nav_next() end, desc = "Goto next mark" },
{ prefix .. "m", "<cmd>Telescope harpoon marks<CR>", desc = "Show marks in Telescope" },
{ prefix, function() end, desc = "󱡀 Harpoon" },
{
prefix .. "t",
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",
},
{
"<C-t>",
function()
local num = tonumber(vim.fn.input "GoTo terminal window number: ")
require("harpoon.term").gotoTerminal(num)
local num = tonumber(vim.fn.input("GoTo 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",
},
{
prefix .. "j",
"<C-p>",
function() require("harpoon.ui").nav_prev() end,
desc = "Goto previous mark",
},
{
"<C-n>",
function() require("harpoon.ui").nav_next() end,
desc = "Goto next mark",
},
{ prefix .. "m", "<cmd>Telescope harpoon marks<CR>", desc = "Show marks in Telescope" },
{
prefix .. "t",
function()
local num = tonumber(vim.fn.input "GoTo Tmux window number: ")
require("harpoon.tmux").gotoTerminal(num)
if running_tmux_seesion 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,
},
},
}

0 comments on commit f1a4ca7

Please sign in to comment.