-
-
Notifications
You must be signed in to change notification settings - Fork 384
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
Can't seem to add absolute path to harpoon list #484
Comments
Ok, got absolute paths working, but they still show up as relative in list: opts[require("harpoon.config").DEFAULT_LIST] = {
add = function() return { value = vim.api.nvim_buf_get_name(0) } end,
}
harpoon:setup(opts) How can I make them show up as absolute as well? Ideally, I would want them to be displayed similar to buffers: relative when they are in cwd, absolute with ~ otherwise. |
Pretty sure you need to use I have spent a decent amount of time trying to get stuff like this to work. If you want an item that you add when in one cwd to show up in the list when you are in another cwd, then you need to change your key to something other than create_list_item = function(_, item)
if item == nil then
item = vim.api.nvim_buf_get_name(
vim.api.nvim_get_current_buf()
)
end
if type(item) == "string" then
local name = require("plenary.path"):new(item):absolute()
local bufnr = vim.fn.bufnr(name, false)
local pos = { 1, 0 }
if bufnr ~= -1 then
pos = vim.api.nvim_win_get_cursor(0)
end
item = {
value = name,
context = {
row = pos[1],
col = pos[2],
},
}
end
return item
end, This will store the absolute path rather than the relative path. I have a PR out (#469) that does it's best to support absolute paths and will show it as an absolute path if it is not in your cwd, but relative to cwd if it is. Check out the conversation in #466 and #467 if you are looking for the display to include something like |
Thanks, that works. The key was already set to be static. local name = require("plenary.path"):new(item):make_relative(work_dir) Where I tried using |
This solution actually fails a bit when using |
In order to solve that, you would need to store the absolute path, rather than the relative path. |
I want to use absolute paths in my harpoon list (my cwd changes based on which project the file belongs to).
I see that
append
takes an item, and tried passing in the absolute path, but it doesn't seem to work:What should I do instead?
The text was updated successfully, but these errors were encountered: