[mini.pick] How to write custom commands with pipe | to builtin.cli?
#1053
-
|
Here I am trying to use proximity-sort with mini-pick. I tried with to directly pass the following commands into command = {
"fd",
"--color=never",
"--type",
"file",
"--hidden",
"--follow",
"--exclude",
".git",
"|",
"proximity-sort",
vim.fn.expand("%:."),
},But nothing was shown. I could make it work as follows: local function files()
local uv = vim.uv
local pipe, stdout = uv.new_pipe(), uv.new_pipe()
uv.spawn("fd", {
args = {
"--color=never",
"--type",
"file",
"--hidden",
"--follow",
"--exclude",
".git",
},
stdio = { nil, pipe, nil },
})
uv.spawn("proximity-sort", {
args = { vim.fn.expand("%:.") },
stdio = { pipe, stdout, nil },
})
local data_feed = {}
local items = nil
stdout:read_start(function(err, data)
assert(not err, err)
if data then return table.insert(data_feed, data) end
items = vim.split(table.concat(data_feed), "\n")
data_feed = nil
stdout:close()
pipe:close()
vim.schedule(function()
MiniPick.start({
source = {
items = items,
},
})
end)
end)
endBut I was wondering if there are other ways to write this? as I could easily do this in local opts = {
cwd = vim.fn.getcwd(),
fzf_opts = {
["--tiebreak"] = "index",
},
cmd = "fd --color=never --type file --hidden --follow --exclude .git",
}
local base = vim.fn.expand("%:.")
opts.cmd = string.format(
"%s | proximity-sort %s",
opts.cmd,
vim.fn.empty(base) == 0 and vim.fn.shellescape(base) or "."
)
require("fzf-lua").files(opts) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Indeed, command in |
Beta Was this translation helpful? Give feedback.
Indeed, command in
builtin.cli()should be a single CLI command (as in: can be used invim.uv.spawn()). The best way I can suggest to implement this is viabuiltin.cli()and itspostprocessfield. It will be called with array of items and should return the array of items. You can apply custom sorting there. If you want to make it async, I think returning empty table while schedulingMiniPick.set_picker_items()with sorted items when they are ready should do the trick.