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
feat!: add grep builtin using `grepprg`
robinwobin.dev
3 months ago
d1759215
368d9746
+79
-5
3 changed files
expand all
collapse all
unified
split
README.md
lua
artio
builtins.lua
plugin
artio.lua
+2
-1
README.md
···
54
54
vim.ui.select = require("artio").select
55
55
56
56
vim.keymap.set("n", "<leader><leader>", "<Plug>(artio-files)")
57
57
-
vim.keymap.set("n", "<leader>fg", "<Plug>(artio-livegrep)")
57
57
+
vim.keymap.set("n", "<leader>fg", "<Plug>(artio-grep)")
58
58
59
59
-- smart file picker
60
60
vim.keymap.set("n", "<leader>ff", "<Plug>(artio-smart)")
···
62
62
-- general built-in pickers
63
63
vim.keymap.set("n", "<leader>fh", "<Plug>(artio-helptags)")
64
64
vim.keymap.set("n", "<leader>fb", "<Plug>(artio-buffers)")
65
65
+
vim.keymap.set("n", "<leader>f/", "<Plug>(artio-buffergrep)")
65
66
vim.keymap.set("n", "<leader>fo", "<Plug>(artio-oldfiles)")
66
67
```
+72
-2
lua/artio/builtins.lua
···
57
57
})
58
58
end
59
59
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
83
+
builtins.grep = function()
84
84
+
local ext = require("vim._extui.shared")
85
85
+
86
86
+
return artio.pick({
87
87
+
items = {},
88
88
+
prompt = "grep",
89
89
+
get_items = function(input)
90
90
+
if input == "" then
91
91
+
return {}
92
92
+
end
93
93
+
94
94
+
local lines = grep(input)
95
95
+
96
96
+
vim.fn.setloclist(ext.wins.cmd, {}, " ", {
97
97
+
title = "grep[" .. input .. "]",
98
98
+
lines = lines,
99
99
+
efm = vim.o.grepformat,
100
100
+
nr = "$",
101
101
+
})
102
102
+
103
103
+
return vim
104
104
+
.iter(ipairs(vim.fn.getloclist(ext.wins.cmd)))
105
105
+
:map(function(i, locitem)
106
106
+
return {
107
107
+
id = i,
108
108
+
v = { vim.fn.bufname(locitem.bufnr), locitem.lnum, locitem.col },
109
109
+
text = locitem.text,
110
110
+
}
111
111
+
end)
112
112
+
:totable()
113
113
+
end,
114
114
+
fn = artio.sorter,
115
115
+
on_close = function(item, _)
116
116
+
vim.schedule(function()
117
117
+
vim.cmd.edit(item[1])
118
118
+
vim.api.nvim_win_set_cursor(0, { item[2], item[3] })
119
119
+
end)
120
120
+
end,
121
121
+
preview_item = function(item)
122
122
+
return vim.fn.bufadd(item[1])
123
123
+
end,
124
124
+
get_icon = config.get().opts.use_icons and function(item)
125
125
+
return require("mini.icons").get("file", item.v[1])
126
126
+
end or nil,
127
127
+
})
128
128
+
end
129
129
+
60
130
local function find_oldfiles()
61
131
return vim
62
132
.iter(vim.v.oldfiles)
···
85
155
})
86
156
end
87
157
88
88
-
builtins.livegrep = function()
158
158
+
builtins.buffergrep = function()
89
159
local win = vim.api.nvim_get_current_win()
90
160
local buf = vim.api.nvim_win_get_buf(win)
91
161
local n = vim.api.nvim_buf_line_count(buf)
···
97
167
local pad = #tostring(lst[#lst])
98
168
99
169
return artio.generic(lst, {
100
100
-
prompt = "livegrep",
170
170
+
prompt = "buffergrep",
101
171
on_close = function(row, _)
102
172
vim.schedule(function()
103
173
vim.api.nvim_win_set_cursor(win, { row, 0 })
+5
-2
plugin/artio.lua
···
35
35
vim.keymap.set("n", "<Plug>(artio-oldfiles)", function()
36
36
return require("artio.builtins").oldfiles()
37
37
end)
38
38
-
vim.keymap.set("n", "<Plug>(artio-livegrep)", function()
39
39
-
return require("artio.builtins").livegrep()
38
38
+
vim.keymap.set("n", "<Plug>(artio-grep)", function()
39
39
+
return require("artio.builtins").grep()
40
40
end)
41
41
vim.keymap.set("n", "<Plug>(artio-helptags)", function()
42
42
return require("artio.builtins").helptags()
43
43
+
end)
44
44
+
vim.keymap.set("n", "<Plug>(artio-buffergrep)", function()
45
45
+
return require("artio.builtins").buffergrep()
43
46
end)
44
47
vim.keymap.set("n", "<Plug>(artio-buffers)", function()
45
48
return require("artio.builtins").buffers()