Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Harpoon 2] There is any way to do the same thing as mark_branch from Harpoon? #502

Closed
marcioflaviof opened this issue Jan 24, 2024 · 4 comments

Comments

@marcioflaviof
Copy link

Hello guys, thanks for this awesome plugin, one feature that I used a lot from the original Harpoon was mark_branch but I didn't see anything like that on Harpoon2, there is any way in Harpoon2 to get this feature?

@erik-schmidt
Copy link

Hi @marcioflaviof,

i was also missing this feature, but eventually found a quick way to add the functionality to harpoon2! I have looked into the main branch how the mark_branch feature actually works. In Harpoon2 you can specify HarpoonSettings key to tell harpoon how the out list key is looked up.

Here is my config (note that I am using lazy.nvim as my package manager):

local Job = require "plenary.job"

local function get_os_command_output(cmd, cwd)
  if type(cmd) ~= "table" then return {} end
  local command = table.remove(cmd, 1)
  local stderr = {}
  local stdout, ret = Job:new({
    command = command,
    args = cmd,
    cwd = cwd,
    on_stderr = function(_, data) table.insert(stderr, data) end,
  }):sync()
  return stdout, ret, stderr
end

return {
  {
    "ThePrimeagen/harpoon",
    branch = "harpoon2",
    dependencies = {
      "nvim-lua/plenary.nvim",
      "nvim-telescope/telescope.nvim",
    },
    opts = {
      settings = {
        save_on_toggle = true,
        sync_on_ui_close = true,
        key = function()
          local branch = get_os_command_output({
            "git",
            "rev-parse",
            "--abbrev-ref",
            "HEAD",
          })[1]

          if branch then
            return vim.loop.cwd() .. "-" .. branch
          else
            return vim.loop.cwd()
          end
        end,
      },
    },
  }

Hope this helps!

@marcioflaviof
Copy link
Author

It worked here, thanks @erik-schmidt

@D0T7
Copy link

D0T7 commented Jun 25, 2024

@erik-schmidt
return vim.loop.cwd() doesn't work on neovim v0.10.0, instead I'm using return vim.fn.getcwd()
Also using this function leads to the loss of the marked files after rebooting nvim, any ideas on why that might be?

@marcioflaviof
Copy link
Author

@erik-schmidt return vim.loop.cwd() doesn't work on neovim v0.10.0, instead I'm using return vim.fn.getcwd() Also using this function leads to the loss of the marked files after rebooting nvim, any ideas on why that might be?

Maybe it can be something related to this

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

No branches or pull requests

3 participants