mirror of
https://github.com/folke/snacks.nvim
synced 2025-07-07 21:25:11 +00:00

## Description More info coming tomorrow. In short: - very fast. pretty much realtime filtering/sorting in huge repos (like 1.7 million files) - extensible - easy to customize the layout (and lots of presets) with `snacks.layout` - simple to create custom pickers - `vim.ui.select` - lots of builtin pickers - uses treesitter highlighting wherever it makes sense - fast lua fuzzy matcher which supports the [fzf syntax](https://junegunn.github.io/fzf/search-syntax/) and additionally supports field filters, like `file:lua$ 'function` There's no snacks picker command, just use lua. ```lua -- all pickers Snacks.picker() -- run files picker Snacks.picker.files(opts) Snacks.picker.pick("files", opts) Snacks.picker.pick({source = "files", ...}) ``` <!-- Describe the big picture of your changes to communicate to the maintainers why we should accept this pull request. --> ## Todo - [x] issue with preview loc not always correct when scrolling fast in list (probably due to `snacks.scroll`) - [x] `grep` (`live_grep`) is sometimes too fast in large repos and can impact ui rendering. Not very noticeable, but something I want to look at. - [x] docs - [x] treesitter highlights are broken. Messed something up somewhere ## Related Issue(s) <!-- If this PR fixes any issues, please link to the issue here. - Fixes #<issue_number> --> ## Screenshots <!-- Add screenshots of the changes if applicable. -->
64 lines
1.9 KiB
Lua
64 lines
1.9 KiB
Lua
local M = {}
|
|
|
|
---@class snacks.picker
|
|
---@field cliphist fun(opts?: snacks.picker.proc.Config): snacks.Picker
|
|
---@field man fun(opts?: snacks.picker.proc.Config): snacks.Picker
|
|
|
|
---@param opts snacks.picker.proc.Config
|
|
---@type snacks.picker.finder
|
|
function M.cliphist(opts)
|
|
return require("snacks.picker.source.proc").proc(vim.tbl_deep_extend("force", {
|
|
cmd = "cliphist",
|
|
args = { "list" },
|
|
---@param item snacks.picker.finder.Item
|
|
transform = function(item)
|
|
local id, content = item.text:match("^(%d+)%s+(.+)$")
|
|
if id and content and not content:find("^%[%[%s+binary data") then
|
|
item.text = content
|
|
setmetatable(item, {
|
|
__index = function(_, k)
|
|
if k == "data" then
|
|
local data = vim.fn.system({ "cliphist", "decode", id })
|
|
rawset(item, "data", data)
|
|
if vim.v.shell_error ~= 0 then
|
|
error(data)
|
|
end
|
|
return data
|
|
elseif k == "preview" then
|
|
return {
|
|
text = item.data,
|
|
ft = "text",
|
|
}
|
|
end
|
|
end,
|
|
})
|
|
else
|
|
return false
|
|
end
|
|
end,
|
|
}, opts or {}))
|
|
end
|
|
|
|
---@param opts snacks.picker.proc.Config
|
|
---@type snacks.picker.finder
|
|
function M.man(opts)
|
|
return require("snacks.picker.source.proc").proc(vim.tbl_deep_extend("force", {
|
|
cmd = "man",
|
|
args = { "-k", "." },
|
|
---@param item snacks.picker.finder.Item
|
|
transform = function(item)
|
|
local page, section, desc = item.text:match("^(%S+)%s*%((%S-)%)%s+-%s+(.+)$")
|
|
if page and section and desc then
|
|
item.section = section
|
|
item.desc = desc
|
|
item.page = page
|
|
item.section = section
|
|
item.ref = ("%s(%s)"):format(item.page, item.section or 1)
|
|
else
|
|
return false
|
|
end
|
|
end,
|
|
}, opts or {}))
|
|
end
|
|
|
|
return M
|