Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
Andre Schaf
4b96003de4 fuzzy find files no plugins 2026-05-12 14:28:39 +02:00

View file

@ -45,3 +45,41 @@ vim.g.clipboard = {
}, },
cache_enable = 0, cache_enable = 0,
} }
local function fzf_open_terminal()
local tmp = vim.fn.tempname()
local cwd = vim.fn.getcwd()
local rg = [[rg --files --hidden --glob "!.git/**" --glob "!node_modules/**" --glob "!.angular/**"]]
local awk = [[awk -F'/' '{dir = (NF>1 ? substr($0, 1, length($0)-length($NF)-1) : "."); printf("%s [%s]\t%s\n", $NF, dir, $0)}']]
local inner = string.format("cd %s && %s | %s | fzf --height 40%% > %s",
vim.fn.shellescape(cwd), rg, awk, vim.fn.shellescape(tmp))
vim.cmd('belowright split')
local bufnr = vim.api.nvim_create_buf(false, true)
vim.api.nvim_win_set_buf(0, bufnr)
-- pass argv form to avoid fish parsing issues
vim.fn.termopen({'bash', '-ic', inner}, {
on_exit = function()
local lines = vim.fn.readfile(tmp)
os.remove(tmp)
if #lines == 0 then
vim.schedule(function()
if vim.api.nvim_buf_is_valid(bufnr) then vim.api.nvim_buf_delete(bufnr, {force=true}) end
end)
return
end
local sel = lines[1]:match("\t(.*)$") or lines[1]
vim.schedule(function()
if vim.api.nvim_buf_is_valid(bufnr) then vim.api.nvim_buf_delete(bufnr, {force=true}) end
vim.cmd('edit ' .. vim.fn.fnameescape(sel))
end)
end,
})
vim.cmd('startinsert')
end
vim.keymap.set('n', '<leader>o', fzf_open_terminal, {noremap=true, silent=true})