Skip to content

Instantly share code, notes, and snippets.

@benlubas
Last active April 27, 2024 12:21
Show Gist options
  • Save benlubas/09254459af633cce1b5ac12d16640f0e to your computer and use it in GitHub Desktop.
Save benlubas/09254459af633cce1b5ac12d16640f0e to your computer and use it in GitHub Desktop.
Harpoon mark files from telescope picker
M = {}
local telescope_utils = require("telescope.actions.utils")
local utils = require("telescope.actions.utils")
local actions = require("telescope.actions")
M.mark_file = function(tb)
actions.drop_all(tb)
actions.add_selection(tb)
telescope_utils.map_selections(tb, function(selection)
local file = selection[1]
-- This lets it work with live grep picker
if selection.filename then
file = selection.filename
end
-- this lets it work with git status picker
if selection.value then
file = selection.filename
end
pcall(require("harpoon.mark").add_file, file)
end)
actions.remove_selection(tb)
end
return M
@benlubas
Copy link
Author

benlubas commented Aug 8, 2023

Okay, I've updated this gist with a missing import and two if statements that let it work with live grep and the git status picker.

Happy to help you troubleshoot if this is still causing issues

@RiteshChepuri
Copy link

Nah,
Its working fine. Thank you!

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