summaryrefslogtreecommitdiff
path: root/scratch/example.lua
blob: 19952dc39e7f73a33e2000982ec5c8574152edfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

local finder = Finder:new {
  'rg %s -l',
  pipeable = true,
  ...
}

local filter = Filter:new {
  "fzf --filter '%s'"
}

local lua_filter = Filter:new {
  function(input, line)
    if string.match(line, input) then
      return true
    end

    return false
  end
}


local picker_read = Picker:new {
  filter = filter,

  previewer = function(window, buffer, line)
    local file = io.open(line, "r")

    local filename = vim.split(line, ':')[1]
    if vim.fn.bufexists(filename) then
      vim.api.nvim_win_set_buf(window, vim.fn.bufnr(filename))
      return
    end

    local lines = {}
    for _ = 1, 100 do
      table.insert(lines, file:read("l"))

      -- TODO: Check if we're out of lines
    end

    -- optionally set the filetype or whatever...
    vim.api.nvim_buf_set_lines(buffer, 0, -1, false, lines)
  end,

  mappings = {
    ["<CR>"] = function(line)
      vim.cmd(string.format('e ', vim.split(line, ':')))
    end,
  },
}

local picker = Picker:new {
  filter = filter,

  -- idk
  previewer = function(window, line)
    vim.api.nvim_win_set_current_window(window)

    -- if is_file_loaded(line) then
    --   lien_number = vim.api.nvim_...

    vim.fn.termopen(string.format(
      'bat --color=always --style=grid %s',
      vim.split(line, ':')[1]
    ))
  end
}