From 69d4cd3899845d84767fa0e2ff9c8234e9dcbf84 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Wed, 15 Jul 2020 00:05:14 -0400 Subject: Initial commit after stream --- scratch/example.lua | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 scratch/example.lua (limited to 'scratch/example.lua') diff --git a/scratch/example.lua b/scratch/example.lua new file mode 100644 index 0000000..19952dc --- /dev/null +++ b/scratch/example.lua @@ -0,0 +1,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 = { + [""] = 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 +} -- cgit v1.2.3