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

Yes this is still working for me.

I'll note that it only works for file pickers, live grep doesn't work with this script. I've been meaning to fix that for a while, just haven't gotten around to it yet.

Could you show me how you're using it? with which picker and which key you've assigned it to?

@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