Skip to content

Commit

Permalink
fix: improve startup time by deferring executable check (#970)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibhagwan committed Dec 28, 2023
1 parent 15734a5 commit 9a4ee4a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lua/fzf-lua/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,18 @@ M.defaults = {
_ctor = previewers.fzf.cmd,
},
bat = {
cmd = vim.fn.executable("batcat") == 1 and "batcat" or "bat",
-- reduce startup time by deferring executable check to previewer constructor (#970)
cmd = function() return vim.fn.executable("batcat") == 1 and "batcat" or "bat" end,
args = "--color=always --style=numbers,changes",
_ctor = previewers.fzf.bat_async,
},
bat_native = {
cmd = vim.fn.executable("batcat") == 1 and "batcat" or "bat",
cmd = function() return vim.fn.executable("batcat") == 1 and "batcat" or "bat" end,
args = "--color=always --style=numbers,changes",
_ctor = previewers.fzf.bat,
},
bat_async = {
cmd = vim.fn.executable("batcat") == 1 and "batcat" or "bat",
cmd = function() return vim.fn.executable("batcat") == 1 and "batcat" or "bat" end,
args = "--color=always --style=numbers,changes",
_ctor = previewers.fzf.bat_async,
},
Expand Down Expand Up @@ -198,8 +199,9 @@ M.defaults = {
codeaction_native = {
_ctor = previewers.fzf.codeaction,
diff_opts = { ctxlen = 3 },
pager = vim.fn.executable("delta") == 1
and "delta --width=$FZF_PREVIEW_COLUMNS" or nil,
pager = function()
return vim.fn.executable("delta") == 1 and "delta --width=$FZF_PREVIEW_COLUMNS" or nil
end,
},
},
}
Expand Down
3 changes: 3 additions & 0 deletions lua/fzf-lua/previewer/codeaction.lua
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ function M.native:new(o, opts, fzf_win)
M.native.super.new(self, o, opts, fzf_win)
setmetatable(self, M.native)
self.pager = opts.preview_pager == nil and o.pager or opts.preview_pager
if type(self.pager) == "function" then
self.pager = self.pager()
end
self.diff_opts = o.diff_opts
return self
end
Expand Down
3 changes: 3 additions & 0 deletions lua/fzf-lua/previewer/fzf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ function Previewer.base:new(o, opts)
o = o or {}
self.type = "cmd";
self.cmd = o.cmd;
if type(self.cmd) == "function" then
self.cmd = self.cmd()
end
self.args = o.args or "";
self.opts = opts;
return self
Expand Down

0 comments on commit 9a4ee4a

Please sign in to comment.