harpoon
harpoon copied to clipboard
Have optional Key per List
What issue are you having that you need harpoon to solve? You can only set a key in the settings, this will work for all lists
Why doesn't the current config help? It would be useful to be able to overwrite the key setting in a per list basis, so I can have a list in cwd and a different list per git branch
I'm not sure I get what you mean. After testing on a project using git-worktree my harpoon2 list updates accordingly when I switch branches.
hmmm.... Maybe it's this: The harpoon list only updates when I change the active branch. However, if I instead navigate to a buffer with a file from a non-active branch then the harpoon list does not update. Is that it?
I'm not having issues with behavior, is a feature request.
I want to have a list that changes with branch, and a different list that only changes with cwd
Oh I see. Actually of I'm not mistaken the default behavior creates and displays lists based on the cwd. That's why when I change branches it works, cause with worktrees each branch lives in a different directory.
So you'd like to be able to add files to a branch list regardless of the cwd set, so whenever you switch branches the list also changes.
I was trying to figure out if it could be done with either the custom lists, or the extend features. Maybe it can be done using both but I'm not really familiar with those yet.
You'd need one extend command to save and another to open lists named after the branch.
Then you'd need to create the two key maps.
Oh I see. Actually of I'm not mistaken the default behavior creates and displays lists based on the cwd. That's why when I change branches it works, cause with worktrees each branch lives in a different directory.
So you'd like to be able to add files to a branch list regardless of the cwd set, so whenever you switch branches the list also changes.
I was trying to figure out if it could be done with either the custom lists, or the extend features. Maybe it can be done using both but I'm not really familiar with those yet.
You'd need one extend command to save and another to open lists named after the branch.
Then you'd need to create the two key maps.
Great idea! I was able to implement that idea with just two sets of keymaps one that uses the default list and another that gets the branch name as the list. My default list is a little customized so I have full paths as the value, but this is what the resulting harpoon.json looks like for the default key:
{
"/Users/max/dev/test-repo": {
"main": [
"{\"value\":\"\\/Users\\/max\\/dev\\/test-repo\\/file02.txt\",\"context\":{\"row\":1,\"col\":0}}"
],
"__harpoon_files": [
"{\"context\":{\"row\":1,\"col\":0},\"value\":\"\\/Users\\/max\\/dev\\/test-repo\\/README.md\"}",
"{\"context\":{\"row\":1,\"col\":0},\"value\":\"\\/Users\\/max\\/dev\\/test-repo\\/file03.txt\"}"
],
"test-branch": [
"{\"context\":{\"row\":1,\"col\":0},\"value\":\"\\/Users\\/max\\/dev\\/test-repo\\/file01.txt\"}"
]
}
}
The default branch is __harpoon_files and the other two lists are the branch names.
Here are the keymaps I set to accomplish this:
local function get_git_branch()
local git_branch = vim.fn.systemlist("git branch --show-current")
if git_branch[1] == "fatal: not a git repository (or any of the parent directories): .git" then
return nil
end
return git_branch[1]
end
vim.keymap.set("n", "<leader>m", function()
Harpoon:list():append()
end)
vim.keymap.set("n", "<leader>h", function()
Harpoon.ui:toggle_quick_menu(Harpoon:list(), {})
end)
vim.keymap.set("n", "<leader>mm", function()
local branch = get_git_branch()
if branch == nil then
return
end
Harpoon:list(branch):append()
end)
vim.keymap.set("n", "<leader>hh", function()
local branch = get_git_branch()
if branch == nil then
return
end
Harpoon.ui:toggle_quick_menu(Harpoon:list(branch), {})
end)
Great @maxrzaw ! It's a lot simpler than I imagined! 😆😂😂
I'll make this happen at some point
I think it should be easy to make, I'm just a bit worried at adding that level of configuration. It makes the project overall more complex
An alternative I'm thinking is to have the list_name as an argument of the key function, and then we could use that if we wanted to