182 lines
4.8 KiB
Lua
182 lines
4.8 KiB
Lua
require('plugins.filetree')
|
|
-- local finder = require('plugins.finder')
|
|
-- finder.setup({
|
|
-- exclude_patterns = { 'node_modules', 'dist', 'build', '.git', '.cache', '.turbo', '*-lock.json' },
|
|
-- use_disk_cache = true,
|
|
-- follow_symlinks = true,
|
|
-- })
|
|
|
|
local file_fd_opts = table.concat({
|
|
'--color=never',
|
|
'--type f',
|
|
'--type l',
|
|
'--hidden',
|
|
'--follow',
|
|
'--exclude .git',
|
|
'--exclude .cache',
|
|
'--exclude .turbo',
|
|
'--exclude node_modules',
|
|
'--exclude dist',
|
|
'--exclude build',
|
|
'--exclude "*-lock.json"',
|
|
'--exclude "*-lock.yaml"',
|
|
}, ' ')
|
|
|
|
local file_rg_opts = table.concat({
|
|
'--color=never',
|
|
'--files',
|
|
'--hidden',
|
|
'--follow',
|
|
'-g "!.git"',
|
|
'-g "!.cache"',
|
|
'-g "!.turbo"',
|
|
'-g "!node_modules"',
|
|
'-g "!dist"',
|
|
'-g "!build"',
|
|
'-g "!*-lock.json"',
|
|
'-g "!*-lock.yaml"',
|
|
}, ' ')
|
|
|
|
local function grep_rg_opts(extra)
|
|
local opts = {
|
|
'--column',
|
|
'--line-number',
|
|
'--no-heading',
|
|
'--color=always',
|
|
'--colors "path:none"',
|
|
'--colors "line:none"',
|
|
'--colors "column:none"',
|
|
'--colors "match:fg:166"',
|
|
'--colors "match:style:bold"',
|
|
'--smart-case',
|
|
'--max-columns=4096',
|
|
'--hidden',
|
|
'--follow',
|
|
'--glob "!.git"',
|
|
'--glob "!.cache"',
|
|
'--glob "!.turbo"',
|
|
'--glob "!node_modules"',
|
|
'--glob "!dist"',
|
|
'--glob "!build"',
|
|
'--glob "!*-lock.json"',
|
|
'--glob "!*-lock.yaml"',
|
|
}
|
|
|
|
vim.list_extend(opts, extra or {})
|
|
table.insert(opts, '-e')
|
|
|
|
return table.concat(opts, ' ')
|
|
end
|
|
|
|
local function uniq_filter()
|
|
return [[awk '!seen[$0]++']]
|
|
end
|
|
|
|
local function files_cmd()
|
|
local fd = vim.fn.executable('fdfind') == 1 and 'fdfind' or vim.fn.executable('fd') == 1 and 'fd' or nil
|
|
if fd then
|
|
return table.concat({
|
|
'(',
|
|
fd .. ' ' .. file_fd_opts .. ' .;',
|
|
fd .. ' ' .. file_fd_opts .. ' --no-ignore --glob ".env*" .;',
|
|
'if [ -d _artifacts ]; then ' .. fd .. ' ' .. file_fd_opts .. ' --no-ignore . _artifacts; fi',
|
|
') | ' .. uniq_filter(),
|
|
}, ' ')
|
|
end
|
|
|
|
if vim.fn.executable('rg') == 1 then
|
|
return table.concat({
|
|
'(',
|
|
'rg ' .. file_rg_opts .. ' .;',
|
|
'rg ' .. file_rg_opts .. ' --no-ignore --glob ".env*" .;',
|
|
'if [ -d _artifacts ]; then rg ' .. file_rg_opts .. ' --no-ignore _artifacts; fi',
|
|
') | ' .. uniq_filter(),
|
|
}, ' ')
|
|
end
|
|
|
|
return nil
|
|
end
|
|
|
|
local function grep_cmd(query)
|
|
local query_arg = query == '<query>' and query or vim.fn.shellescape(query or '')
|
|
local normal_rg = 'rg ' .. grep_rg_opts()
|
|
local ignored_rg = 'rg ' .. grep_rg_opts({ '--no-ignore' })
|
|
local env_rg = 'rg ' .. grep_rg_opts({ '--no-ignore', '--glob ".env*"' })
|
|
|
|
return table.concat({
|
|
'(',
|
|
normal_rg .. ' ' .. query_arg .. ' .;',
|
|
env_rg .. ' ' .. query_arg .. ' .;',
|
|
'if [ -d _artifacts ]; then ' .. ignored_rg .. ' ' .. query_arg .. ' _artifacts; fi',
|
|
') | ' .. uniq_filter(),
|
|
}, ' '), query
|
|
end
|
|
|
|
require('fzf-lua').setup({
|
|
fzf_colors = {
|
|
['fg'] = { 'fg', 'PickerNormal' },
|
|
['bg'] = { 'bg', 'PickerNormal' },
|
|
['fg+'] = { 'fg', 'PickerSelection' },
|
|
['bg+'] = { 'bg', 'PickerSelection' },
|
|
['hl'] = { 'fg', 'PickerMatch' },
|
|
['hl+'] = { 'fg', 'PickerMatch' },
|
|
['info'] = { 'fg', 'PickerMuted' },
|
|
['prompt'] = { 'fg', 'PickerPrompt' },
|
|
['pointer'] = { 'fg', 'PickerPrompt' },
|
|
['marker'] = { 'fg', 'PickerPrompt' },
|
|
['spinner'] = { 'fg', 'PickerPrompt' },
|
|
['header'] = { 'fg', 'PickerMuted' },
|
|
['border'] = { 'fg', 'PickerBorder' },
|
|
['separator'] = { 'fg', 'PickerBorder' },
|
|
['gutter'] = '-1',
|
|
},
|
|
hls = {
|
|
normal = 'PickerNormal',
|
|
border = 'PickerBorder',
|
|
title = 'PickerTitle',
|
|
title_flags = 'PickerMuted',
|
|
preview_normal = 'PickerPreview',
|
|
preview_border = 'PickerPreviewBorder',
|
|
preview_title = 'PickerTitle',
|
|
cursorline = 'PickerSelection',
|
|
cursorlinenr = 'PickerMuted',
|
|
search = 'PickerMatch',
|
|
header_bind = 'PickerMuted',
|
|
header_text = 'PickerMuted',
|
|
path_colnr = 'PickerMuted',
|
|
path_linenr = 'PickerMuted',
|
|
},
|
|
winopts = {
|
|
split = function()
|
|
vim.cmd(('botright %dnew +set\\ nobl'):format(math.max(12, math.floor(vim.o.lines * 0.35))))
|
|
end,
|
|
backdrop = 100,
|
|
treesitter = false,
|
|
preview = {
|
|
default = 'builtin',
|
|
delay = 0,
|
|
layout = 'flex',
|
|
horizontal = 'right:55%',
|
|
vertical = 'down:45%',
|
|
flip_columns = 120,
|
|
},
|
|
},
|
|
files = {
|
|
cmd = files_cmd(),
|
|
fd_opts = file_fd_opts,
|
|
rg_opts = file_rg_opts,
|
|
},
|
|
grep = {
|
|
rg_opts = grep_rg_opts(),
|
|
fn_transform_cmd = grep_cmd,
|
|
},
|
|
})
|
|
local fzf = require('fzf-lua')
|
|
|
|
-- vim.keymap.set('n', '<leader>f', finder.files)
|
|
-- vim.keymap.set('n', '<leader>g', finder.grep)
|
|
-- vim.keymap.set('n', '<leader>fc', finder.clear_cache)
|
|
-- vim.keymap.set('n', '<leader>fD', finder.diagnose)
|
|
vim.keymap.set('n', '<leader>f', fzf.files)
|
|
vim.keymap.set('n', '<leader>g', fzf.live_grep)
|