From a7957b2bdc5c3ce86092544448b4eb6ebcbb645e Mon Sep 17 00:00:00 2001 From: Senghan Bright Date: Wed, 7 Oct 2020 22:01:47 +0200 Subject: feat: Manpages finder (output of apropos) (#134) First edition. Sometimes weird things can happen with the previewer, but I think I got it 99% working. * feat: Manpages finder (output of apropos) * fixup: Add previewer and fix comments Co-authored-by: TJ DeVries --- lua/telescope/builtin.lua | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'lua/telescope/builtin.lua') diff --git a/lua/telescope/builtin.lua b/lua/telescope/builtin.lua index fc63f1f..de56da7 100644 --- a/lua/telescope/builtin.lua +++ b/lua/telescope/builtin.lua @@ -737,4 +737,43 @@ builtin.current_buffer_fuzzy_find = function(opts) }):find() end +builtin.man_pages = function(opts) + opts = opts or {} + + local cmd = opts.man_cmd or "apropos --sections=1 ''" + + local f = assert(io.popen(cmd, 'r')) + local pages = assert(f:read('*a')) + f:close() + + local lines = {} + for s in pages:gmatch("[^\r\n]+") do + table.insert(lines, s) + end + + pickers.new(opts, { + prompt = 'Man', + finder = finders.new_table { + results = lines, + entry_maker = make_entry.gen_from_apropos(opts), + }, + previewer = previewers.man.new(opts), + sorter = sorters.get_generic_fuzzy_sorter(), + attach_mappings = function(prompt_bufnr, map) + local view_manpage = function() + local selection = actions.get_selected_entry(prompt_bufnr) + + actions.close(prompt_bufnr) + print(vim.inspect(selection.value)) + vim.cmd("Man " .. selection.value) + end + + map('i', '', view_manpage) + map('n', '', view_manpage) + + return true + end + }):find() +end + return builtin -- cgit v1.2.3