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

[Feature request] Possibility to have a Git branch context List #625

Open
t1gu1 opened this issue Aug 5, 2024 · 6 comments
Open

[Feature request] Possibility to have a Git branch context List #625

t1gu1 opened this issue Aug 5, 2024 · 6 comments

Comments

@t1gu1
Copy link

t1gu1 commented Aug 5, 2024

What issue are you having that you need harpoon to solve?
First, I really love harpoon! But I always find myself to delete all files in harpoon context to reset it when starting a different feature when creating a new branch in projects I works on.

What proposed api changes are you suggesting?
It would be really nice to have something like a Global harpoon for the project context and another for a git branch context, since the files for a new feature are generally different.

How to?

  • Just a bool to switch between global context and git branch context(Feature context) would be perfect!
  • Add a way to manage the "save of harpoon context" related to the current/active git branch.
@t1gu1
Copy link
Author

t1gu1 commented Aug 5, 2024

Similar to that i guess
#616

@t1gu1
Copy link
Author

t1gu1 commented Aug 5, 2024

There is somethings with a key that seems to already make that possible i guess?
If it is the case, it could be nice to have an example in the readme.

@t1gu1
Copy link
Author

t1gu1 commented Aug 5, 2024

I found how to do it.

Here is the required functions and how to use it.

-- P.S. branchFeature is just an example here and should be replace by your git branch name

-- Add the file in the branchFeature
require("harpoon"):list("branchFeature"):add()

-- Show the list branchFeature
require("harpoon").ui:toggle_quick_menu(require("harpoon"):list("branchFeature"))

I will test it and i may create a PR to add that info in the readme?
Other than that i guess we can close this Feature request.

@t1gu1 t1gu1 changed the title [Feature request] Git branch context > Global Project context or maybe the two? [Feature request] Possibility to have a Git branch context List Aug 5, 2024
@t1gu1
Copy link
Author

t1gu1 commented Aug 5, 2024

Here is a more complete example:

{
    "ThePrimeagen/harpoon",
    branch = "harpoon2",
   opts = {
	 settings = {
		 save_on_toggle = true,
		 sync_on_ui_close = true,
          },
    },
    config = function()
        require("harpoon").setup()
    end,
    dependencies = {
        "nvim-lua/plenary.nvim",
        "nvim-telescope/telescope.nvim"
    },
    keys = {
        {
            "<leader>a",
            function()
                local pipe = io.popen("git branch --show-current")
                repeat
                    local c = pipe:read(4 * 1048576)
                    if c then
                        require("harpoon"):list(c):add()
                    end
                until not c
                pipe:close()
            end,
            desc = "Harpoon - Add file related to current git branch"
        },
        {
            "<leader><leader>e",
            function()
                local pipe = io.popen("git branch --show-current")
                repeat
                    local c = pipe:read(4 * 1048576)
                    if c then
                        require("harpoon").ui:toggle_quick_menu(require("harpoon"):list(c))
                    end
                until not c
                pipe:close()
            end,
            desc = "Harpoon - Toggle quick menu related to current git branch"
        }
    }
}

@g-pavlik
Copy link

g-pavlik commented Sep 24, 2024

@t1gu1 I think this can simplify your config (I took the crucial part for taking the branch name from you, which I didn't know how to do):

harpoon:setup({
  settings = {
    key = function()
      local pipe = io.popen("git branch --show-current")
      if pipe then
        local c = pipe:read("*l"):match("^%s*(.-)%s*$")
        pipe:close()
        return c
      end
      return nil
    end,
  },
})

key is a config option that allows you to tell Harpoon how to make a "key" to look up a particular list (in other words: you re-implemented a bit of harpoon logic, which can be avoided)

@g-pavlik
Copy link

BTW, there appears to be a bug in the key option (that your version didn't suffer from, @t1gu1), but there's a workaround: #565 (comment)

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

2 participants