feat(picker): picker:dir() to get the dir of the item (when a directory) or it's parent (when a file)

This commit is contained in:
Folke Lemaitre 2025-02-04 17:10:17 +01:00
parent 6235f44b11
commit 969608ab79
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -553,6 +553,17 @@ function M:current(opts)
return ret
end
--- Returns the directory of the current item or the cwd.
--- When the item is a directory, return item path,
--- otherwise return the directory of the item.
function M:dir()
local item = self:current()
if item then
return Snacks.picker.util.dir(item)
end
return self:cwd()
end
--- Get the selected items.
--- If `fallback=true` and there is no selection, return the current item.
---@param opts? {fallback?: boolean} default is `false`