@@ -227,6 +227,58 @@ function M.normalize_opts(opts, globals, __resume_key) ---@diagnostic disable
227227 opts = M .resume_opts (opts )
228228 end
229229
230+ local executable = function (binary , fncerr , strerr )
231+ if binary and vim .fn .executable (binary ) ~= 1 then
232+ fncerr ((" '%s' is not a valid executable, %s" ):format (binary , strerr ))
233+ return false
234+ end
235+ return true
236+ end
237+
238+ -- Validate the fzf binary & version dependency
239+ opts .fzf_bin = opts .fzf_bin or M .globals .fzf_bin
240+ opts .fzf_bin = opts .fzf_bin and libuv .expand (opts .fzf_bin ) or nil
241+ if not opts .fzf_bin or
242+ not executable (opts .fzf_bin , utils .warn , " fallback to 'fzf'." ) then
243+ -- default|fallback to fzf
244+ opts .fzf_bin = " fzf"
245+ -- try fzf plugin if fzf is not installed globally
246+ if vim .fn .executable (opts .fzf_bin ) ~= 1 then
247+ local ok , fzf_plug = pcall (vim .api .nvim_call_function , " fzf#exec" , {})
248+ if ok and fzf_plug then
249+ opts .fzf_bin = fzf_plug
250+ end
251+ end
252+ if not executable (opts .fzf_bin , utils .error ,
253+ " aborting. Please make sure 'fzf' is in installed." ) then
254+ return nil
255+ end
256+ end
257+
258+ -- enforce fzf minimum requirements
259+ vim .g .fzf_lua_fzf_version = nil
260+ if opts .fzf_bin :match (" sk$" ) then
261+ local SK_VERSION , rc , err = utils .sk_version (opts )
262+ opts .__SK_VERSION = SK_VERSION
263+ if not opts .__SK_VERSION then
264+ utils .error (" 'sk --version' failed with error %s: %s" , rc , err )
265+ return nil
266+ end
267+ else
268+ local FZF_VERSION , rc , err = utils .fzf_version (opts )
269+ opts .__FZF_VERSION = FZF_VERSION
270+ vim .g .fzf_lua_fzf_version = FZF_VERSION
271+ if not opts .__FZF_VERSION then
272+ utils .error (" 'fzf --version' failed with error %s: %s" , rc , err )
273+ return nil
274+ elseif not utils .has (opts , " fzf" , { 0 , 36 }) then
275+ utils .error (" fzf version %s is lower than minimum (0.36), aborting." ,
276+ utils .ver2str (opts .__FZF_VERSION ))
277+ return nil
278+ end
279+ end
280+
281+
230282 local function convert_bool_opts ()
231283 -- Enforce conversion of boolean options that are tables with `enabled`
232284 -- property, i.e. `winopts.treesitter = true` will be converted to
@@ -656,59 +708,6 @@ function M.normalize_opts(opts, globals, __resume_key) ---@diagnostic disable
656708 -- test for valid git_repo
657709 opts .git_icons = opts .git_icons and path .is_git_repo (opts , true )
658710
659- local executable = function (binary , fncerr , strerr )
660- if binary and vim .fn .executable (binary ) ~= 1 then
661- fncerr ((" '%s' is not a valid executable, %s" ):format (binary , strerr ))
662- return false
663- end
664- return true
665- end
666-
667- opts .fzf_bin = opts .fzf_bin or M .globals .fzf_bin
668- opts .fzf_bin = opts .fzf_bin and libuv .expand (opts .fzf_bin ) or nil
669- if not opts .fzf_bin or
670- not executable (opts .fzf_bin , utils .warn , " fallback to 'fzf'." ) then
671- -- default|fallback to fzf
672- opts .fzf_bin = " fzf"
673- -- try fzf plugin if fzf is not installed globally
674- if vim .fn .executable (opts .fzf_bin ) ~= 1 then
675- local ok , fzf_plug = pcall (vim .api .nvim_call_function , " fzf#exec" , {})
676- if ok and fzf_plug then
677- opts .fzf_bin = fzf_plug
678- end
679- end
680- if not executable (opts .fzf_bin , utils .error ,
681- " aborting. Please make sure 'fzf' is in installed." ) then
682- return nil
683- end
684- end
685-
686- -- are we using skim?
687- opts ._is_skim = opts .fzf_bin :match (" sk$" ) ~= nil
688-
689- -- enforce fzf minimum requirements
690- vim .g .fzf_lua_fzf_version = nil
691- if not opts ._is_skim then
692- local FZF_VERSION , rc , err = utils .fzf_version (opts )
693- opts .__FZF_VERSION = FZF_VERSION
694- vim .g .fzf_lua_fzf_version = FZF_VERSION
695- if not opts .__FZF_VERSION then
696- utils .error (" 'fzf --version' failed with error %s: %s" , rc , err )
697- return nil
698- elseif not utils .has (opts , " fzf" , { 0 , 36 }) then
699- utils .error (" fzf version %s is lower than minimum (0.36), aborting." ,
700- utils .ver2str (opts .__FZF_VERSION ))
701- return nil
702- end
703- else
704- local SK_VERSION , rc , err = utils .sk_version (opts )
705- opts .__SK_VERSION = SK_VERSION
706- if not opts .__SK_VERSION then
707- utils .error (" 'sk --version' failed with error %s: %s" , rc , err )
708- return nil
709- end
710- end
711-
712711 if utils .has (opts , " fzf" , { 0 , 53 })
713712 -- `_multiline` is used to override `multiline` inherited from `defaults = {}`
714713 and opts .multiline and opts ._multiline ~= false then
0 commit comments