Skip to content

Commit b983b6c

Browse files
committed
fix(FZF_DEFAULT_OPTS): strip --preview-window (#1107)
1 parent 618c4de commit b983b6c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lua/fzf-lua/fzf.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,23 @@ function M.raw_fzf(contents, fzf_cli_args, opts)
266266
["SHELL"] = shell_cmd[1],
267267
["FZF_DEFAULT_COMMAND"] = FZF_DEFAULT_COMMAND,
268268
["SKIM_DEFAULT_COMMAND"] = FZF_DEFAULT_COMMAND,
269+
["FZF_DEFAULT_OPTS"] = (function()
270+
-- Newer style `--preview-window` options in FZF_DEFAULT_OPTS such as:
271+
-- --preview-window "right,50%,hidden,<60(up,70%,hidden)"
272+
-- prevents our previewer from working properly, since there is never
273+
-- a reason to inherit `preview-window` options it can be safely stripped
274+
-- from FZF_DEFAULT_OPTS (#1107)
275+
local default_opts = os.getenv("FZF_DEFAULT_OPTS")
276+
if not default_opts then return end
277+
local patterns = { "--preview-window" }
278+
for _, p in ipairs(patterns) do
279+
-- remove flag end of string
280+
default_opts = default_opts:gsub(utils.lua_regex_escape(p) .. "[=%s]+[^%-]+%s-$", "")
281+
-- remove flag start/mid of string
282+
default_opts = default_opts:gsub(utils.lua_regex_escape(p) .. "[=%s]+.-%s+%-%-", " --")
283+
end
284+
return default_opts
285+
end)()
269286
},
270287
on_exit = function(_, rc, _)
271288
local output = {}

0 commit comments

Comments
 (0)