internal: move git diff retrieval to make_entry.preprocess

main
bhagwan 3 years ago
parent 7fa17b85bb
commit 828aceb3a3

@ -252,6 +252,10 @@ M.mt_cmd_wrapper = function(opts)
return libuv.spawn_nvim_fzf_cmd(opts,
function(x)
return make_entry.file(opts, x)
end,
function(o)
-- setup opts.cwd and git diff files
return make_entry.preprocess(o)
end)
end
end
@ -259,6 +263,7 @@ end
-- shortcuts to make_entry
M.get_devicon = make_entry.get_devicon
M.make_entry_file = make_entry.file
M.make_entry_preprocess = make_entry.preprocess
M.make_entry_lcol = function(_, entry)
if not entry then return nil end
@ -322,14 +327,8 @@ M.fzf_files = function(opts, contents)
if not opts then return end
-- reset git tracking
opts.diff_files = nil
coroutine.wrap(function ()
-- setup opts.cwd and git diff files
make_entry.preprocess(opts)
local selected = M.fzf(opts, contents or opts.fzf_fn)
if opts.post_select_cb then

@ -234,10 +234,15 @@ end
M.async_spawn = coroutinify(M.spawn)
M.spawn_nvim_fzf_cmd = function(opts, fn_transform)
M.spawn_nvim_fzf_cmd = function(opts, fn_transform, fn_preprocess)
assert(not fn_transform or type(fn_transform) == 'function')
if fn_preprocess and type(fn_preprocess) == 'function' then
-- run the preprocessing fn
fn_preprocess(opts)
end
return function(_, fzf_cb, _)
local function on_finish(_, _)

@ -26,8 +26,7 @@ M.status = function(opts)
if opts.preview then
opts.preview = vim.fn.shellescape(path.git_cwd(opts.preview, opts.cwd))
end
local contents = libuv.spawn_nvim_fzf_cmd(
{ cmd = opts.cmd, cwd = opts.cwd, pid_cb = opts._pid_cb },
local contents = libuv.spawn_nvim_fzf_cmd(opts,
function(x)
-- greedy match anything after last space
local f = x:match("[^ ]*$")
@ -38,6 +37,9 @@ M.status = function(opts)
f = f:match('[^"]*$')
end
return core.make_entry_file(opts, f)
end,
function(o)
return core.make_entry_preprocess(o)
end)
opts = core.set_header(opts, 2)
return core.fzf_files(opts, contents)

Loading…
Cancel
Save