From 2e44eeb06bdca50b969f1dd83deb2579d6867c15 Mon Sep 17 00:00:00 2001 From: Tomas Mirchev Date: Sat, 30 May 2026 05:40:43 +0300 Subject: [PATCH] Update search and helm filetype config --- lua/core/filetypes.lua | 27 ++++-- lua/modules/navigation.lua | 165 +++++++++++++++++++++++++------------ 2 files changed, 132 insertions(+), 60 deletions(-) diff --git a/lua/core/filetypes.lua b/lua/core/filetypes.lua index a15b55f..f88ecd5 100644 --- a/lua/core/filetypes.lua +++ b/lua/core/filetypes.lua @@ -1,11 +1,26 @@ +local function has_ancestor_file(path, filename) + local dir = vim.fs.dirname(path) + while dir and dir ~= '' do + if vim.uv.fs_stat(vim.fs.joinpath(dir, filename)) then + return true + end + + local parent = vim.fs.dirname(dir) + if not parent or parent == dir then + return false + end + dir = parent + end + return false +end + vim.filetype.add({ pattern = { - ['.*/templates/.*%.ya?ml'] = 'helm', - ['.*/manifests/.*%.ya?ml'] = 'helm', - ['.*/crds/.*%.ya?ml'] = 'helm', - ['.*/kubernetes/.*%.ya?ml'] = 'helm', - ['.*/k8s/.*%.ya?ml'] = 'helm', - ['.*/charts/.*%.ya?ml'] = 'helm', + ['.*/templates/.*%.ya?ml'] = function(path) + if has_ancestor_file(path, 'Chart.yaml') then + return 'helm' + end + end, }, extension = { gotmpl = 'helm', diff --git a/lua/modules/navigation.lua b/lua/modules/navigation.lua index 3e88227..d7c7513 100644 --- a/lua/modules/navigation.lua +++ b/lua/modules/navigation.lua @@ -6,6 +6,112 @@ require('plugins.filetree') -- 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 == '' 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' }, @@ -56,62 +162,13 @@ require('fzf-lua').setup({ }, }, files = { - follow = true, - 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"', - }, ' '), - 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"', - }, ' '), + cmd = files_cmd(), + fd_opts = file_fd_opts, + rg_opts = file_rg_opts, }, grep = { - rg_opts = table.concat({ - '--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"', - '-e', - }, ' '), + rg_opts = grep_rg_opts(), + fn_transform_cmd = grep_cmd, }, }) local fzf = require('fzf-lua')