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-09 14:34:07 +00:00
|
|
|
|
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()
|
2024-04-09 14:34:07 +00:00
|
|
|
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
|
|
|
|
|
2024-04-09 14:34:07 +00:00
|
|
|
-- Commands
|
|
|
|
api.nvim_create_user_command("HarpoonClear", function()
|
2024-04-28 19:10:40 +00:00
|
|
|
harpoon:list():clear()
|
2024-04-09 14:34:07 +00:00
|
|
|
end, { bang = true })
|
2024-04-09 18:00:35 +00:00
|
|
|
api.nvim_create_user_command("HarpoonAdd", function()
|
2024-04-28 19:10:40 +00:00
|
|
|
harpoon:list():add()
|
2024-04-09 18:00:35 +00:00
|
|
|
end, { bang = true })
|
2024-04-09 14:34:07 +00:00
|
|
|
api.nvim_create_user_command("HarpoonToggleFile", function()
|
2024-04-28 19:10:40 +00:00
|
|
|
toggle_mark()
|
2024-04-09 14:34:07 +00:00
|
|
|
end, { bang = true })
|
|
|
|
api.nvim_create_user_command("HarpoonUI", function()
|
2024-04-28 19:10:40 +00:00
|
|
|
toggle_telescope(harpoon:list())
|
2024-04-09 14:34:07 +00:00
|
|
|
end, { bang = true })
|