all repos — dotfiles @ f32f507400d14c2fbaac570b600beaef602ad56a

my *nix dotfiles

config/nvim/lua/fzy/fzy.lua (view raw)

 1local M = {}
 2local api = vim.api
 3local o = vim.o
 4local fn = vim.fn
 5
 6function M.fzy_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    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        stdout = f:read('*all')
37        exit_fn(stdout)
38        f:close()
39        os.remove(file)
40    end})
41end
42return M