Skip to content

Add (some) support to terminal lists#672

Open
saucoide wants to merge 1 commit into
ThePrimeagen:harpoon2from
saucoide:terminal-list
Open

Add (some) support to terminal lists#672
saucoide wants to merge 1 commit into
ThePrimeagen:harpoon2from
saucoide:terminal-list

Conversation

@saucoide
Copy link
Copy Markdown

This is what i've been using since i had to stop using harpoon 1, decided to
clean it up a bit and submit it in case it is helpful for anyone else even if
it doesnt get merged

Summary of what it does:

  • Adds a HarpoonTermList as a specialized list type for managing terminal buffers
  • toggle_quick_menu works, deleting a terminal from there will kill the buffer too
  • You can send commands with :send_command and also a selection or the current line with :send_selection

Adding __is_harpoon_list is pretty ugly but I dont know how to better tell
apart from a table with config to be merged and table with a full instance of
list

Usage would be something like This

local harpoon = require('harpoon')

harpoon.setup({ 
    settings = {
        save_on_toggle = true,
    },
    ["terms"] = require("harpoon.terms"):new()
})

-- Buffers
vim.keymap.set( "n", "<leader>a", function() harpoon:list():add() end, { desc = "Harpoon: Add file" })
vim.keymap.set( "n", "<leader>hh", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end, { desc = "Harpoon: Toggle quick menu" })
vim.keymap.set( "n", "<leader>1", function() harpoon:list():select(1) end, { desc = "Harpoon: Go to file 1" })
vim.keymap.set( "n", "<leader>2", function() harpoon:list():select(2) end, { desc = "Harpoon: Go to file 2" })
vim.keymap.set( "n", "<leader>3", function() harpoon:list():select(3) end, { desc = "Harpoon: Go to file 3" })
vim.keymap.set( "n", "<leader>4", function() harpoon:list():select(4) end, { desc = "Harpoon: Go to file 4" })
vim.keymap.set( "n", "<leader>5", function() harpoon:list():select(5) end, { desc = "Harpoon: Go to file 5" })

-- Terminals
vim.keymap.set("n", "<leader>tt", function() harpoon.ui:toggle_quick_menu(harpoon:list("terms")) end, { desc = "Show harpoon terminal menu" })
-- nagivation
vim.keymap.set("n", "<leader>t1", function() harpoon:list("terms"):select(1) end, { desc = "Harpoon: Go to Terminal 1" })
vim.keymap.set("n", "<leader>t2", function() harpoon:list("terms"):select(2) end, { desc = "Harpoon: Go to Terminal 2" })
-- send specific commands
vim.keymap.set("n", "<C-l>1", function() harpoon:list("terms"):send_command(1, "clear") end, { desc = "Harpoon: Clear Terminal 1" })
vim.keymap.set("n", "<C-l>2", function() harpoon:list("terms"):send_command(2, "clear") end, { desc = "Harpoon: Clear Terminal 2" })
-- send selections
vim.keymap.set({"n", "v"}, "<C-CR>1", function() harpoon:list("terms"):send_selection(1, true) end, { desc = "Harpoon: Current selection to Terminal 1" })
vim.keymap.set({"n", "v"}, "<C-CR>2", function() harpoon:list("terms"):send_selection(2, true) end, { desc = "Harpoon: Current selection to Terminal 2" })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant