diff options
| author | smolck <46855713+smolck@users.noreply.github.com> | 2020-09-06 22:07:51 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-06 23:07:51 -0400 |
| commit | 2592586533868aede5c254f4599601bf53f699da (patch) | |
| tree | 10ceb10951dab034ce2d0f8e625f3bf1734eaf67 /lua/telescope/builtin.lua | |
| parent | 675e240383454e96f0275062b1a67f8b55cc2798 (diff) | |
View the planets (#12)
* add planets viewer builtin
* Remove print statement
* Don't use fzf & echo
* Add all planets as files and refactor accordingly
* Remove planets.lua
* add the moon
* example ofe how to do this without ls everywhere
* fix rebase and update to new style
Co-authored-by: TJ DeVries <devries.timothyj@gmail.com>
Diffstat (limited to 'lua/telescope/builtin.lua')
| -rw-r--r-- | lua/telescope/builtin.lua | 41 |
1 files changed, 41 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 |
