From 53cd37031e3408722a901ede2fdfe76507d7ac9e Mon Sep 17 00:00:00 2001 From: bhagwan Date: Sat, 25 Jun 2022 01:09:50 -0700 Subject: [PATCH] feat(fzf_exec): improved API, easy command transform --- lua/fzf-lua/core.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lua/fzf-lua/core.lua b/lua/fzf-lua/core.lua index fafd5b8..3646910 100644 --- a/lua/fzf-lua/core.lua +++ b/lua/fzf-lua/core.lua @@ -50,12 +50,20 @@ M.fzf_wrap = function(opts, contents, fn_selected) end) end -M.fzf_exec = function(contents, opts, fn_selected) - fn_selected = fn_selected or function(selected) +M.fzf_exec = function(contents, opts) + opts = opts or {} + opts.fn_selected = opts.fn_selected or function(selected) if not selected then return end - actions.act(opts and opts.actions or nil, selected) + actions.act(opts.actions, selected, opts) + end + -- wrapper for command transformer + if type(contents) == 'string' and opts.fn_transform then + contents = libuv.spawn_nvim_fzf_cmd({ + cmd = contents, + cwd = opts.cwd, + }, opts.fn_transform) end - return M.fzf_wrap(opts, contents, fn_selected)() + return M.fzf_wrap(opts, contents)() end M.fzf = function(opts, contents)