@@ -155,9 +155,10 @@ M.fzf_exec = function(contents, opts)
155155 -- the API accepts both tables and functions which we "stringify"
156156 -- We also send string commands as stringify is also responsible
157157 -- for multiprocess wrapping of shell commands with processing
158- contents = contents and shell .stringify (contents , opts ) or nil
158+ shell .clear_protected ()
159+ contents = contents and shell .stringify (contents , opts , nil , true ) or nil
159160 assert (contents == nil or type (contents ) == " string" , " contents must be of type string" )
160- return M .fzf_wrap (contents , opts )
161+ return M .fzf_wrap (contents , opts , true )
161162end
162163
163164--- @param contents string | fun ( query : string ): string | string[] | function
@@ -172,12 +173,14 @@ M.fzf_live = function(contents, opts)
172173 -- AKA "live": fzf acts as a selector only (fuzzy matching is disabled)
173174 -- each keypress reloads fzf's input usually based on the typed query
174175 -- utilizes fzf's 'change:reload' event or skim's "interactive" mode
175- opts .fn_reload = shell .stringify (contents , opts )
176+ -- convert "reload" actions to fzf's `reload` binds
177+ -- convert "exec_silent" actions to fzf's `execute-silent` binds
178+ shell .clear_protected ()
179+ opts .fn_reload = shell .stringify (contents , opts , nil , true )
176180 local fzf_field_index = M .fzf_field_index (opts )
177181 local cmd = M .expand_query (opts .fn_reload , fzf_field_index )
178- opts = M .setup_fzf_interactive_flags (cmd , fzf_field_index , opts )
179- contents = opts .__fzf_init_cmd
180- return M .fzf_wrap (contents , opts )
182+ contents , opts = M .setup_fzf_interactive_flags (cmd , fzf_field_index , opts )
183+ return M .fzf_wrap (contents , opts , true )
181184end
182185
183186M .fzf_resume = function (opts )
@@ -191,15 +194,19 @@ M.fzf_resume = function(opts)
191194 assert (opts == config .__resume_data .opts )
192195 opts = M .set_header (opts , opts .headers or {})
193196 opts .cwd = opts .cwd and libuv .expand (opts .cwd ) or nil
194- opts .__resuming = true
195- M .fzf_exec (config .__resume_data .contents , config .__resume_data .opts )
197+ M .fzf_wrap (config .__resume_data .contents , config .__resume_data .opts )
196198end
197199
198200--- @param contents string ?
199201--- @param opts table
202+ --- @param convert_actions boolean ?
200203--- @return thread , string , table
201- M .fzf_wrap = function (contents , opts )
204+ M .fzf_wrap = function (contents , opts , convert_actions )
202205 opts = opts or {}
206+ if convert_actions then
207+ opts = M .convert_reload_actions (contents , opts )
208+ opts = M .convert_exec_silent_actions (opts )
209+ end
203210 local _co
204211 local wrapped = coroutine.wrap (function ()
205212 _co = coroutine.running ()
@@ -316,11 +323,6 @@ M.fzf = function(contents, opts)
316323 opts .actions [k ] = actions .dummy_abort
317324 end
318325 end
319- if not opts .__resuming then
320- -- `opts.__resuming` is only set from `fzf_resume`, since we
321- -- not resuming clear the shell protected functions registry
322- shell .clear_protected ()
323- end
324326 -- store last call opts for resume
325327 config .resume_set (nil , opts .__call_opts , opts )
326328 -- caller specified not to resume this call (used by "builtin" provider)
@@ -393,10 +395,6 @@ M.fzf = function(contents, opts)
393395
394396 fzf_win :attach_previewer (previewer )
395397 local fzf_bufnr = fzf_win :create ()
396- -- convert "reload" actions to fzf's `reload` binds
397- -- convert "exec_silent" actions to fzf's `execute-silent` binds
398- opts = M .convert_reload_actions (contents , opts )
399- opts = M .convert_exec_silent_actions (opts )
400398 local selected , exit_code = fzf .raw_fzf (contents , M .build_fzf_cli (opts , fzf_win ),
401399 {
402400 fzf_bin = opts .fzf_bin ,
@@ -998,7 +996,7 @@ local patch_shell_action = function(v, opts)
998996 items = (zero_matched and zero_selected ) and {} or items
999997 end
1000998 v .fn (items , opts )
1001- end , opts , field_index )
999+ end , opts , field_index , true )
10021000end
10031001
10041002-- converts actions defined with "reload=true" to use fzf's `reload` bind
@@ -1084,7 +1082,8 @@ M.convert_reload_actions = function(reload_cmd, opts)
10841082 -- NOTE: this fixes existence of both load as function and rebind, e.g. git_status with:
10851083 -- setup({ keymap = { fzf = { true, load = function() _G._fzf_load_called = true end } } }
10861084 if type (opts .keymap .fzf .load ) == " function" then
1087- opts .keymap .fzf .load = " execute-silent:" .. shell .stringify_data (opts .keymap .fzf .load , opts )
1085+ opts .keymap .fzf .load = " execute-silent:"
1086+ .. shell .stringify_data (opts .keymap .fzf .load , opts , nil , true )
10881087 end
10891088 if rebind and type (opts .keymap .fzf .load ) == " string" then
10901089 return string.format (" %s+%s" , rebind , opts .keymap .fzf .load )
@@ -1148,7 +1147,7 @@ end
11481147--- @param command string
11491148--- @param fzf_field_index string
11501149--- @param opts table
1151- --- @return table
1150+ --- @return string ?, table
11521151M .setup_fzf_interactive_flags = function (command , fzf_field_index , opts )
11531152 -- query cannot be 'nil'
11541153 opts .query = opts .query or " "
@@ -1190,8 +1189,6 @@ M.setup_fzf_interactive_flags = function(command, fzf_field_index, opts)
11901189 )
11911190
11921191 if opts ._is_skim then
1193- -- skim interactive mode does not need a piped command
1194- opts .__fzf_init_cmd = nil
11951192 opts .prompt = opts .__prompt or opts .prompt or opts .fzf_opts [" --prompt" ]
11961193 if opts .prompt then
11971194 opts .fzf_opts [" --prompt" ] = opts .prompt :match (" [^%*]+" )
@@ -1215,10 +1212,6 @@ M.setup_fzf_interactive_flags = function(command, fzf_field_index, opts)
12151212 opts ._fzf_cli_args = string.format (" --interactive --cmd %s" ,
12161213 libuv .shellescape (no_query_condi .. reload_command ))
12171214 else
1218- -- **send an empty table to avoid running $FZF_DEFAULT_COMMAND
1219- -- The above seems to create a hang in some systems
1220- -- use `true` as $FZF_DEFAULT_COMMAND instead (#510)
1221- opts .__fzf_init_cmd = utils .shell_nop ()
12221215 if opts .exec_empty_query or (opts .query and # opts .query > 0 ) then
12231216 local q = not utils .__IS_WINDOWS and opts .query
12241217 or libuv .escape_fzf (opts .query , utils .has (opts , " fzf" , { 0 , 52 }) and 0.52 or 0 )
@@ -1234,9 +1227,13 @@ M.setup_fzf_interactive_flags = function(command, fzf_field_index, opts)
12341227 end
12351228 opts ._fzf_cli_args = string.format (" --bind=%s" , libuv .shellescape (
12361229 string.format (" change:reload:%s%s" , no_query_condi , reload_command )))
1230+ if utils .has (opts , " fzf" , { 0 , 35 }) then
1231+ opts ._fzf_cli_args = opts ._fzf_cli_args .. string.format (" --bind=%s" ,
1232+ libuv .shellescape (string.format (" start:reload:%s%s" , no_query_condi , reload_command )))
1233+ end
12371234 end
12381235
1239- return opts
1236+ return utils . shell_nop (), opts
12401237end
12411238
12421239-- query placeholder for "live" queries
0 commit comments