all repos — dotfiles @ 11f0020301b3d3446b27b60aeaf948664e96b15f

my *nix dotfiles

nvim/lua/fuzzy/fuzzy.lua (view raw)

 1local M = {}
 2local api = vim.api
 3local o = vim.o
 4local fn = vim.fn
 5
 6function M.fuzzy_search(cmd, exit_fn)
 7    local width = o.columns - 4
 8    local height = 11
 9    if (o.columns >= 85) then
10        width = 80
11    end
12
13    local buf = api.nvim_create_buf(false, true)
14    api.nvim_buf_set_option(buf, 'bufhidden', 'wipe')
15    api.nvim_buf_set_option(buf, 'modifiable', true)
16
17    api.nvim_open_win(
18        buf,
19        true,
20        {
21            relative = 'editor',
22            style = 'minimal',
23            noautocmd = true,
24            border = 'rounded',
25            width = width,
26            height = height,
27            col = math.min((o.columns - width) / 2),
28            row = math.min((o.lines - height) / 2 - 1),
29        }
30    )
31    local file = vim.fn.tempname()
32    api.nvim_command('startinsert!')
33
34    vim.fn.termopen(cmd .. ' > ' .. file, {on_exit = function()
35        local f = io.open(file, 'r')
36        local stdout = f:read('*all')
37        exit_fn(stdout)
38        f:close()
39        os.remove(file)
40    end})
41end
42return M