jones-nvim-config/lua/config/harpoon.lua

49 lines
1.4 KiB
Lua
Raw Normal View History

2024-04-07 21:27:43 +00:00
local api = vim.api
local harpoon = require("harpoon")
harpoon.setup({})
2024-04-07 21:29:37 +00:00
-- basic telescope configuration
local conf = require("telescope.config").values
local function toggle_telescope(harpoon_files)
2024-04-28 19:10:40 +00:00
local file_paths = {}
for _, item in ipairs(harpoon_files.items) do
table.insert(file_paths, item.value)
end
2024-04-28 19:10:40 +00:00
require("telescope.pickers")
.new({}, {
prompt_title = "Harpoon",
finder = require("telescope.finders").new_table({
results = file_paths,
}),
previewer = conf.file_previewer({}),
sorter = conf.generic_sorter({}),
})
:find()
end
2024-04-11 20:00:37 +00:00
2024-04-11 00:00:12 +00:00
local function toggle_mark()
2024-04-28 19:10:40 +00:00
local current_file = api.nvim_buf_get_name(0) -- Get the current buffer's file path
local item, index = harpoon:list():get_by_value(current_file)
if item then
harpoon:list():remove_at(index)
print("Removed from Harpoon: " .. current_file)
else
harpoon:list():add({ value = current_file })
print("Added to Harpoon: " .. current_file)
end
2024-04-07 21:29:37 +00:00
end
-- Commands
api.nvim_create_user_command("HarpoonClear", function()
2024-04-28 19:10:40 +00:00
harpoon:list():clear()
end, { bang = true })
api.nvim_create_user_command("HarpoonAdd", function()
2024-04-28 19:10:40 +00:00
harpoon:list():add()
end, { bang = true })
api.nvim_create_user_command("HarpoonToggleFile", function()
2024-04-28 19:10:40 +00:00
toggle_mark()
end, { bang = true })
api.nvim_create_user_command("HarpoonUI", function()
2024-04-28 19:10:40 +00:00
toggle_telescope(harpoon:list())
end, { bang = true })