Dashboard - shorten file name #1955
-
In my dashboard config. I added a section for the project files that are relatively to cwd:
Assuming my cwd is foo/bar/, the dashboard section will be like this
I was wondering if there is a way to shorten the file name show in the "recent_files" section to be relative to the cwd:
|
Beta Was this translation helpful? Give feedback.
Answered by
drowning-cat
Jun 8, 2025
Replies: 1 comment
-
https://github.com/folke/snacks.nvim/blob/main/docs/dashboard.md#%EF%B8%8F-config Note There is no way to differentiate which section an item is related to. dashboard = {
formats = {
file = function(item, ctx)
-- local fname = vim.fn.fnamemodify(item.file, ":~")
local fname = vim.fn.fnamemodify(item.file, ":.")
fname = ctx.width and #fname > ctx.width and vim.fn.pathshorten(fname) or fname
if #fname > ctx.width then
local dir = vim.fn.fnamemodify(fname, ":h")
local file = vim.fn.fnamemodify(fname, ":t")
if dir and file then
file = file:sub(-(ctx.width - #dir - 2))
fname = dir .. "/…" .. file
end
end
local dir, file = fname:match("^(.*)/(.+)$")
return dir and { { dir .. "/", hl = "dir" }, { file, hl = "file" } } or { { fname, hl = "file" } }
end,
},
}, |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
kliu99
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/folke/snacks.nvim/blob/main/docs/dashboard.md#%EF%B8%8F-config
Note
There is no way to differentiate which section an item is related to.
It would be nice to pass some field to
ctx
to be able to distinguish which section an item belongs to.