harpoon
harpoon copied to clipboard
Too long file names has problems
it would be perfect if it only shows last 2 folders so it would be better to see where to navigate.
or maybe a function that splits the string by / and returns only 2 or 3 folder paths. that makes u help how many folder path u want to see in each harpoon item path string
Okay I got something working here which gets the bases on the width of the plenary window then you could truncate each folder to how many lines you like or get the file + parent directory
Harpoon Setup
local harpoon = require("harpoon")
local truncateAt = require('config.harpoon-truncate')
local Path = require("plenary.path")
local function normalize_path(buf_name, root)
return Path:new(buf_name):make_relative(root)
end
harpoon:setup({
default = {
create_list_item = function(config, name)
name = name
or normalize_path(
vim.api.nvim_buf_get_name(
vim.api.nvim_get_current_buf()
),
config.get_root_dir()
)
local bufnr = vim.fn.bufnr(name, false)
local fileDirectory = vim.fn.expand('%:p:h:t')
local fileName = vim.fn.expand('%:t')
local pathname = fileDirectory .. '/' .. fileName
local newName = name;
if (string.len(name) >= truncateAt.trucateLength(name)) then
newName = Path:new(name):shorten(2)
-- or
-- newName = pathname
end
local pos = { 1, 0 }
if bufnr ~= -1 then
pos = vim.api.nvim_win_get_cursor(0)
end
return {
value = name,
context = {
row = pos[1],
col = pos[2],
name = newName
},
}
end,
display = function(list_item)
return list_item.context.name
end,
}
})
Truncate file
local HarpoonText = {}
function HarpoonText:trucateLength()
local win = vim.api.nvim_list_uis()
local ui_fallback_width = 69;
local ui_width_ratio = 0.62569;
local width = ui_fallback_width
if #win > 0 then
-- no ackshual reason for 0.62569, just looks complicated, and i want
-- to make my boss think i am smart
width = math.floor(win[1].width * ui_width_ratio)
end
local truncateAt = math.floor((vim.o.columns - width) / 2) - 1
return truncateAt
end
return HarpoonText
it's not perfect but should aleviate some of your issues with the length
Yeah figured out another way so this should be a bit better
local harpoon = require("harpoon")
local Path = require("plenary.path")
local function normalize_path(buf_name, root)
return Path:new(buf_name):make_relative(root)
end
harpoon:setup({
default = {
create_list_item = function(config, name)
name = name
or normalize_path(
vim.api.nvim_buf_get_name(
vim.api.nvim_get_current_buf()
),
config.get_root_dir()
)
local bufnr = vim.fn.bufnr(name, false)
local pos = { 1, 0 }
if bufnr ~= -1 then
pos = vim.api.nvim_win_get_cursor(0)
end
return {
value = vim.fn.expand('%:p'),
context = {
row = pos[1],
col = pos[2],
name = name
},
}
end,
display = function(list_item)
local name = list_item.context.name
local windowWidth = vim.api.nvim_win_get_width(0)
local ui_fallback_width = 69;
local ui_width_ratio = 0.62569;
local truncateAt = math.floor(windowWidth * ui_width_ratio)
if truncateAt < ui_fallback_width then
truncateAt = ui_fallback_width
end
if (string.len(name) >= truncateAt) then
name = Path:new(name):shorten(2)
end
return name
end,
}
})