minimal extui fuzzy finder for neovim

refactor: create builtins

+74 -57
+2
.nvim.lua
··· 1 + vim.cmd([[ nnoremap <leader>ff <Plug>(picker-find) ]]) 2 + vim.cmd([[ noremap <leader>r <cmd>restart<cr> ]])
+53
lua/artio/builtins.lua
··· 1 + local function lzrq(modname) 2 + return setmetatable({}, { 3 + __index = function(_, key) 4 + return require(modname)[key] 5 + end, 6 + }) 7 + end 8 + 9 + local artio = lzrq("artio") 10 + 11 + local builtins = {} 12 + 13 + local findprg = "fd -p -t f --color=never" 14 + 15 + local function find_files(match) 16 + if not findprg then 17 + return {} 18 + end 19 + local farg = string.format("'%s'", match or "") 20 + local findcmd, n = findprg:gsub("%$%*", farg) 21 + if n == 0 then 22 + findcmd = findcmd .. " " .. farg 23 + end 24 + local fn = function(o) 25 + local src = o.stderr 26 + if o.code == 0 then 27 + src = o.stdout 28 + end 29 + src = src 30 + local lines = vim.split(src, "\n", { trimempty = true }) 31 + return lines 32 + end 33 + return fn(vim 34 + .system({ vim.o.shell, "-c", findcmd }, { 35 + text = true, 36 + }) 37 + :wait()) 38 + end 39 + 40 + builtins.files = function() 41 + local lst = find_files() 42 + 43 + return artio.generic(lst, { 44 + prompt = "files", 45 + on_close = function(text, _) 46 + vim.schedule(function() 47 + vim.cmd.edit(text) 48 + end) 49 + end, 50 + }) 51 + end 52 + 53 + return builtins
+18 -56
lua/artio/init.lua
··· 1 1 local artio = {} 2 2 3 - local function lzrq(modname) 4 - return setmetatable({}, { 5 - __index = function(_, key) 6 - return require(modname)[key] 7 - end, 8 - }) 9 - end 3 + ---@param lst string[] 4 + artio.sorter = function(lst) 5 + return function(input) 6 + if not lst or #lst == 0 then 7 + return {} 8 + end 10 9 11 - local Picker = lzrq("artio.picker") 12 - 13 - local findprg = "fd -p -t f --color=never" 14 - 15 - local function find_files(match) 16 - if not findprg then 17 - return {} 18 - end 19 - local farg = string.format("'%s'", match or '') 20 - local findcmd, n = findprg:gsub("%$%*", farg) 21 - if n == 0 then 22 - findcmd = findcmd .. " " .. farg 23 - end 24 - local fn = function(o) 25 - local src = o.stderr 26 - if o.code == 0 then 27 - src = o.stdout 28 - end 29 - src = src 30 - local lines = vim.split(src, "\n", { trimempty = true }) 31 - return lines 10 + local matches = vim.fn.matchfuzzypos(lst, input) 11 + return vim 12 + .iter(ipairs(matches[1])) 13 + :map(function(index, v) 14 + return { v, matches[2][index] } 15 + end) 16 + :totable() 32 17 end 33 - return fn(vim 34 - .system({ vim.o.shell, "-c", findcmd }, { 35 - text = true, 36 - }) 37 - :wait()) 38 18 end 39 19 40 - artio.files = function() 41 - return artio.pick({ 42 - prompt = "files", 43 - fn = function(input) 44 - local lst = find_files() 45 - if not lst or #lst == 0 then 46 - return {} 47 - end 48 - 49 - local matches = vim.fn.matchfuzzypos(lst, input) 50 - return vim 51 - .iter(ipairs(matches[1])) 52 - :map(function(index, v) 53 - return { v, matches[2][index] } 54 - end) 55 - :totable() 56 - end, 57 - on_close = function(text, _) 58 - vim.schedule(function() 59 - vim.cmd.edit(text) 60 - end) 61 - end, 62 - }) 20 + artio.generic = function(lst, props) 21 + return artio.pick(vim.tbl_deep_extend("force", { 22 + fn = artio.sorter(lst), 23 + }, props)) 63 24 end 64 25 65 26 artio.pick = function(...) 27 + local Picker = require("artio.picker") 66 28 return Picker:new(...):open() 67 29 end 68 30
+1 -1
plugin/artio.lua
··· 36 36 }) 37 37 38 38 vim.keymap.set("n", "<Plug>(picker-find)", function() 39 - return require("artio").files() 39 + return require("artio.builtins").files() 40 40 end)