feat(picker.format): filename_only option

This commit is contained in:
Folke Lemaitre 2025-01-23 19:52:01 +01:00
parent b86d90e3e9
commit 0396bdfc3e
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
2 changed files with 6 additions and 1 deletions

View file

@ -74,7 +74,7 @@ local M = {}
---@field format? string|snacks.picker.format|string format function or preset
---@field finder? string|snacks.picker.finder|snacks.picker.finder.multi finder function or preset
---@field preview? snacks.picker.preview|string preview function or preset
---@field matcher? snacks.picker.matcher.Config matcher config
---@field matcher? snacks.picker.matcher.Config|{} matcher config
---@field sort? snacks.picker.sort|snacks.picker.sort.Config sort function or config
---@field transform? string|snacks.picker.transform transform/filter function
--- UI
@ -134,6 +134,7 @@ local defaults = {
file = {
filename_first = false, -- display filename before the file path
truncate = 40, -- truncate the file path to (roughly) this length
filename_only = false, -- only show the filename
},
selected = {
show_always = false, -- only show the selected column when there are multiple selections

View file

@ -42,6 +42,10 @@ function M.filename(item, picker)
end
local dir, file = path:match("^(.*)/(.+)$")
if picker.opts.formatters.file.filename_only then
dir = nil
path = vim.fn.fnamemodify(path, ":t")
end
if file and dir then
if picker.opts.formatters.file.filename_first then
ret[#ret + 1] = { file, "SnacksPickerFile", field = "file" }