diff options
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/telescope/builtin.lua | 41 | ||||
| -rw-r--r-- | lua/telescope/finders.lua | 2 | ||||
| -rw-r--r-- | lua/telescope/previewers.lua | 16 |
3 files changed, 59 insertions, 0 deletions
diff --git a/lua/telescope/builtin.lua b/lua/telescope/builtin.lua index 4eae327..fe2528e 100644 --- a/lua/telescope/builtin.lua +++ b/lua/telescope/builtin.lua @@ -426,4 +426,45 @@ builtin.treesitter = function(opts) }):find() end +builtin.planets = function(opts) + opts = opts or {} + local show_pluto = opts.show_pluto or false + + local sourced_file = require('plenary.debug_utils').sourced_filepath() + local base_directory = vim.fn.fnamemodify(sourced_file, ":h:h:h") + + local globbed_files = vim.fn.globpath(base_directory .. '/data/memes/planets/', '*', true, true) + local acceptable_files = {} + for _, v in ipairs(globbed_files) do + if not show_pluto and v:find("pluto") then + else + table.insert(acceptable_files,vim.fn.fnamemodify(v, ':t')) + end + end + + pickers.new { + prompt = 'Planets', + finder = finders.new_table { + results = acceptable_files, + entry_maker = function(line) + return { + ordinal = line, + display = line, + filename = base_directory .. '/data/memes/planets/' .. line, + } + end + }, + previewer = previewers.cat.new(opts), + sorter = sorters.get_norcalli_sorter(), + attach_mappings = function(prompt_bufnr, map) + map('i', '<CR>', function() + local selection = actions.get_selected_entry(prompt_bufnr) + actions.close(prompt_bufnr) + + print("Enjoy astronomy! You viewed:", selection.display) + end) + end, + }:find() +end + return builtin diff --git a/lua/telescope/finders.lua b/lua/telescope/finders.lua index 3957f26..d3e2f61 100644 --- a/lua/telescope/finders.lua +++ b/lua/telescope/finders.lua @@ -120,6 +120,8 @@ function JobFinder:_find(prompt, process_result, process_complete) maximum_results = self.maximum_results, + writer = opts.writer and Job:new(opts.writer) or nil, + on_stdout = on_output, on_stderr = on_output, diff --git a/lua/telescope/previewers.lua b/lua/telescope/previewers.lua index 493a2f6..5f9268d 100644 --- a/lua/telescope/previewers.lua +++ b/lua/telescope/previewers.lua @@ -12,6 +12,7 @@ Previewer.__index = Previewer local bat_options = " --style=grid --paging=always " local previewer_ns = vim.api.nvim_create_namespace('telescope.previewers') + -- --terminal-width=%s -- TODO: We shoudl make sure that all our terminals close all the way. @@ -317,6 +318,21 @@ previewers.help = defaulter(function(_) } end, {}) +previewers.planet_previewer = previewers.new { + preview_fn = function(self, entry, status) + local bufnr = vim.api.nvim_create_buf(false, true) + + vim.api.nvim_win_set_buf(status.preview_win, bufnr) + + local termopen_command = "bat " .. entry.value + + -- HACK! Requires `termopen` to accept buffer argument. + vim.cmd(string.format("noautocmd call win_gotoid(%s)", status.preview_win)) + vim.fn.termopen(termopen_command) + vim.cmd(string.format("noautocmd call win_gotoid(%s)", status.prompt_win)) + end +} + previewers.Previewer = Previewer return previewers |
