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 `make_cmd()` fn
robinwobin.dev
3 months ago
fb6f30b5
b001a106
+32
-49
1 changed file
expand all
collapse all
unified
split
lua
artio
builtins.lua
+32
-49
lua/artio/builtins.lua
···
9
9
local artio = lzrq("artio")
10
10
local config = lzrq("artio.config")
11
11
12
12
-
local builtins = {}
12
12
+
local function cmd_callback(o)
13
13
+
local src = o.stderr
14
14
+
if o.code == 0 then
15
15
+
src = o.stdout
16
16
+
end
17
17
+
src = src
18
18
+
local lines = vim.split(src, "\n", { trimempty = true })
19
19
+
return lines
20
20
+
end
13
21
14
14
-
local findprg = "fd -H -p -t f --color=never"
15
15
-
16
16
-
local function find_files(match)
17
17
-
if not findprg then
18
18
-
return {}
19
19
-
end
20
20
-
local farg = string.format("'%s'", match or "")
21
21
-
local findcmd, n = findprg:gsub("%$%*", farg)
22
22
-
if n == 0 then
23
23
-
findcmd = findcmd .. " " .. farg
24
24
-
end
25
25
-
local fn = function(o)
26
26
-
local src = o.stderr
27
27
-
if o.code == 0 then
28
28
-
src = o.stdout
22
22
+
---@param prg? string
23
23
+
---@return fun(arg?: string): string[]
24
24
+
local function make_cmd(prg)
25
25
+
return function(arg)
26
26
+
if not prg then
27
27
+
return {}
28
28
+
end
29
29
+
arg = string.format("'%s'", arg or "")
30
30
+
local cmd, n = prg:gsub("%$%*", arg)
31
31
+
if n == 0 then
32
32
+
cmd = ("%s %s"):format(prg, arg)
29
33
end
30
30
-
src = src
31
31
-
local lines = vim.split(src, "\n", { trimempty = true })
32
32
-
return lines
34
34
+
return cmd_callback(vim
35
35
+
.system({ vim.o.shell, "-c", cmd }, {
36
36
+
text = true,
37
37
+
})
38
38
+
:wait())
33
39
end
34
34
-
return fn(vim
35
35
-
.system({ vim.o.shell, "-c", findcmd }, {
36
36
-
text = true,
37
37
-
})
38
38
-
:wait())
39
40
end
40
41
42
42
+
local builtins = {}
43
43
+
44
44
+
local findprg = "fd -H -p -t f --color=never"
45
45
+
41
46
builtins.files = function()
42
42
-
local lst = find_files()
47
47
+
local lst = make_cmd(findprg)()
43
48
44
49
return artio.generic(lst, {
45
50
prompt = "files",
···
57
62
})
58
63
end
59
64
60
60
-
local function grep(input)
61
61
-
input = input or ""
62
62
-
local grepcmd, n = vim.o.grepprg:gsub("%$%*", input)
63
63
-
if n == 0 then
64
64
-
grepcmd = grepcmd .. " " .. input
65
65
-
end
66
66
-
67
67
-
local fn = function(o)
68
68
-
local src = o.stderr
69
69
-
if o.code == 0 then
70
70
-
src = o.stdout
71
71
-
end
72
72
-
src = src
73
73
-
local lines = vim.split(src, "\n", { trimempty = true })
74
74
-
return lines
75
75
-
end
76
76
-
return fn(vim
77
77
-
.system({ vim.o.shell, "-c", grepcmd }, {
78
78
-
text = true,
79
79
-
})
80
80
-
:wait())
81
81
-
end
82
82
-
83
65
builtins.grep = function()
84
66
local ext = require("vim._extui.shared")
67
67
+
local grepcmd = make_cmd(vim.o.grepprg)
85
68
86
69
return artio.pick({
87
70
items = {},
···
91
74
return {}
92
75
end
93
76
94
94
-
local lines = grep(input)
77
77
+
local lines = grepcmd(input)
95
78
96
79
vim.fn.setloclist(ext.wins.cmd, {}, " ", {
97
80
title = "grep[" .. input .. "]",