🐻 minimal ui2 fuzzy finder for Neovim codeberg.org/comfysage/artio.nvim
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(utils): expose utils module

robin 68341e9e f77e15e4

+58 -54
+8 -54
lua/artio/builtins.lua
··· 8 8 9 9 local artio = lzrq("artio") 10 10 local config = lzrq("artio.config") 11 + local utils = lzrq("artio.utils") 11 12 12 13 local function extend(t1, t2) 13 14 return vim.tbl_deep_extend("force", t1, t2) 14 - end 15 - 16 - local function cmd_callback(o) 17 - local src = o.stderr 18 - if o.code == 0 then 19 - src = o.stdout 20 - end 21 - src = src 22 - local lines = vim.split(src, "\n", { trimempty = true }) 23 - return lines 24 - end 25 - 26 - ---@param prg? string 27 - ---@return fun(arg?: string): string[] 28 - local function make_cmd(prg) 29 - return function(arg) 30 - if not prg then 31 - return {} 32 - end 33 - arg = string.format("'%s'", arg or "") 34 - local cmd, n = prg:gsub("%$%*", arg) 35 - if n == 0 then 36 - cmd = ("%s %s"):format(prg, arg) 37 - end 38 - return cmd_callback(vim 39 - .system({ vim.o.shell, "-c", cmd }, { 40 - text = true, 41 - }) 42 - :wait()) 43 - end 44 15 end 45 16 46 17 local builtins = {} 47 18 48 - local function make_setqflist(fn) 49 - return function(self, co) 50 - vim.fn.setqflist(vim 51 - .iter(ipairs(self.matches)) 52 - :map(function(_, match) 53 - local item = self.items[match[1]] 54 - local qfitem = fn(item) 55 - return qfitem 56 - end) 57 - :totable()) 58 - vim.schedule(function() 59 - vim.cmd.copen() 60 - end) 61 - coroutine.resume(co, 1) 62 - end 63 - end 64 - 65 19 local findprg = "fd -H -p -t f --color=never" 66 20 67 21 builtins.files = function(props) 68 22 props = props or {} 69 23 props.findprg = props.findprg or findprg 70 24 71 - local lst = make_cmd(props.findprg)() 25 + local lst = utils.make_cmd(props.findprg)() 72 26 73 27 return artio.generic( 74 28 lst, ··· 86 40 return vim.fn.bufadd(item) 87 41 end, 88 42 actions = { 89 - setqflist = make_setqflist(function(item) 43 + setqflist = utils.make_setqflist(function(item) 90 44 return { filename = item.v } 91 45 end), 92 46 }, ··· 101 55 props = props or {} 102 56 103 57 local ext = require("vim._extui.shared") 104 - local grepcmd = make_cmd(vim.o.grepprg) 58 + local grepcmd = utils.make_cmd(vim.o.grepprg) 105 59 106 60 return artio.pick(extend({ 107 61 items = {}, ··· 149 103 return require("mini.icons").get("file", item.v[1]) 150 104 end or nil, 151 105 actions = { 152 - setqflist = make_setqflist(function(item) 106 + setqflist = utils.make_setqflist(function(item) 153 107 return { filename = item.v[1], lnum = item.v[2], col = item.v[3] } 154 108 end), 155 109 }, ··· 188 142 return vim.fn.bufadd(item) 189 143 end, 190 144 actions = { 191 - setqflist = make_setqflist(function(item) 145 + setqflist = utils.make_setqflist(function(item) 192 146 return { filename = item.v } 193 147 end), 194 148 }, ··· 322 276 currentfile = vim.fs.abspath(currentfile) 323 277 324 278 props.findprg = props.findprg or findprg 325 - local lst = make_cmd(props.findprg)() 279 + local lst = utils.make_cmd(props.findprg)() 326 280 327 281 local pwd = vim.fn.getcwd() 328 282 local recentlst = vim ··· 371 325 return vim.fn.bufadd(item) 372 326 end, 373 327 actions = { 374 - setqflist = make_setqflist(function(item) 328 + setqflist = utils.make_setqflist(function(item) 375 329 return { filename = item.v } 376 330 end), 377 331 },
+50
lua/artio/utils.lua
··· 1 + local utils = {} 2 + 3 + local function cmd_callback(o) 4 + local src = o.stderr 5 + if o.code == 0 then 6 + src = o.stdout 7 + end 8 + src = src 9 + local lines = vim.split(src, "\n", { trimempty = true }) 10 + return lines 11 + end 12 + 13 + ---@param prg? string 14 + ---@return fun(arg?: string): string[] 15 + function utils.make_cmd(prg) 16 + return function(arg) 17 + if not prg then 18 + return {} 19 + end 20 + arg = string.format("'%s'", arg or "") 21 + local cmd, n = prg:gsub("%$%*", arg) 22 + if n == 0 then 23 + cmd = ("%s %s"):format(prg, arg) 24 + end 25 + return cmd_callback(vim 26 + .system({ vim.o.shell, "-c", cmd }, { 27 + text = true, 28 + }) 29 + :wait()) 30 + end 31 + end 32 + 33 + function utils.make_setqflist(fn) 34 + return function(self, co) 35 + vim.fn.setqflist(vim 36 + .iter(ipairs(self.matches)) 37 + :map(function(_, match) 38 + local item = self.items[match[1]] 39 + local qfitem = fn(item) 40 + return qfitem 41 + end) 42 + :totable()) 43 + vim.schedule(function() 44 + vim.cmd.copen() 45 + end) 46 + coroutine.resume(co, 1) 47 + end 48 + end 49 + 50 + return utils