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