feat(file_ignore_patterns): consult the wiki link below

https://github.com/ibhagwan/fzf-lua/wiki#file-ignore-patterns
main
bhagwan 2 years ago
parent ee19eda2e3
commit 4707adc1ec

@ -736,6 +736,19 @@ function M.normalize_opts(opts, defaults)
opts[k] or {}, utils.tbl_deep_clone(M.globals[k]) or {})
end
-- Merge arrays from globals|defaults, can't use 'vim.tbl_xxx'
-- for these as they only work for maps, ie. '{ key = value }'
for _, k in ipairs({ 'file_ignore_patterns' }) do
for _, m in ipairs({ defaults, M.globals }) do
if m[k] then
for _, item in ipairs(m[k]) do
if not opts[k] then opts[k] = {} end
table.insert(opts[k], item)
end
end
end
end
-- these options are copied from globals unless specifically set
-- also check if we need to override 'opts.prompt' from cli args
-- if we don't override 'opts.prompt' 'FzfWin.save_query' will

@ -426,6 +426,7 @@ M.mt_cmd_wrapper = function(opts)
"color_icons",
"path_shorten",
"strip_cwd_prefix",
"file_ignore_patterns",
"rg_glob",
"__module__",
}

@ -42,13 +42,13 @@ local function find_last_newline(str)
end
end
--[[ local function find_next_newline(str, start_idx)
local function find_next_newline(str, start_idx)
for i=start_idx or 1,#str do
if string_byte(str, i) == 10 then
return i
end
end
end ]]
end
local function process_kill(pid, signal)
if not pid or not tonumber(pid) then return false end
@ -93,7 +93,6 @@ M.spawn = function(opts, fn_transform, fn_done)
local error_pipe = uv.new_pipe(false)
local write_cb_count = 0
local prev_line_content = nil
-- local num_lines = 0
if opts.fn_transform then fn_transform = opts.fn_transform end
@ -149,33 +148,42 @@ M.spawn = function(opts, fn_transform, fn_done)
end)
end
local function process_lines(data)
-- This is the old function used, worked very well
-- but couldn't handle 'fn_transform' nil retval
-- which we need for 'file_ignore_patterns'
--[[ local function process_lines(data)
-- assert(#data<=66560) -- 65K
write_cb(data:gsub("[^\n]+",
function(x)
return fn_transform(x)
end))
end
end ]]
--[[ local function process_lines(data)
local function process_lines(data)
local lines = {}
local start_idx = 1
repeat
num_lines = num_lines + 1
local nl_idx = find_next_newline(data, start_idx)
local line = data:sub(start_idx, nl_idx)
local line = data:sub(start_idx, nl_idx-1)
-- makes no sense to feed lines
-- bigger than 1024 bytes into fzf
if #line > 1024 then
local msg =
("long line detected, consider adding '--max-columns=512' to ripgrep options:\n %s")
:format(utils.strip_ansi_coloring(line):sub(1,60))
vim.defer_fn(function()
utils.warn(msg)
end, 0)
line = line:sub(1,512) .. '\n'
line = line:sub(1,1024)
-- io.stderr:write(string.format("[Fzf-lua] long line detected (%db), "
-- .. "consider adding '--max-columns=512' to ripgrep options: %s\n",
-- #line, line:sub(1,256)))
end
write_cb(fn_transform(line))
line = fn_transform(line)
if line then table.insert(lines, line) end
start_idx = nl_idx + 1
until start_idx >= #data
end --]]
-- testing shows better performance writing the entire
-- table at once as opposed to calling 'write_cb' for
-- every line after 'fn_transform'
if #lines > 0 then
write_cb(table.concat(lines, "\n").."\n")
end
end
local read_cb = function(err, data)

@ -303,9 +303,6 @@ M.file = function(x, opts)
local ret = {}
local icon, hl
local file = utils.strip_ansi_coloring(string.match(x, '[^:]*'))
-- TODO: this can cause issues with files/grep/live_grep
-- process_lines gsub will replace the entry with nil
-- **low priority as we never use 'cwd_only' with files/grep
if opts.cwd_only and path.starts_with_separator(file) then
local cwd = opts.cwd or vim.loop.cwd()
if not path.is_relative(file, cwd) then
@ -331,6 +328,15 @@ M.file = function(x, opts)
if path.starts_with_separator(x) then
x = path.HOME_to_tilde(x)
end
-- only check for ignored patterns after './' was
-- stripped and path was transformed to relative
if opts.file_ignore_patterns then
for _, pattern in ipairs(opts.file_ignore_patterns) do
if #pattern>0 and x:match(pattern) then
return nil
end
end
end
if opts.path_shorten then
x = path.shorten(x, tonumber(opts.path_shorten))
end

@ -68,6 +68,8 @@ M.status = function(opts)
f1, f2 = f1:match("(.*)%s%->%s(.*)")
end
f1 = f1 and make_entry.file(f1, opts)
-- accomodate 'file_ignore_patterns'
if not f1 then return end
f2 = f2 and make_entry.file(f2, opts)
local staged = git_iconify(x:sub(1,1):gsub("?", " "))
local unstaged = git_iconify(x:sub(2,2))

@ -66,6 +66,8 @@ M.oldfiles = function(opts)
end
-- for 'file_ignore_patterns' to work on relative paths
opts.cwd = opts.cwd or vim.loop.cwd()
opts = core.set_header(opts, opts.headers or {"cwd"})
return core.fzf_exec(contents, opts)
end

Loading…
Cancel
Save