diff options
| author | Senghan Bright <senghan.bright@deltaprojects.com> | 2020-10-07 22:01:47 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-07 16:01:47 -0400 |
| commit | a7957b2bdc5c3ce86092544448b4eb6ebcbb645e (patch) | |
| tree | 4f566baf6741c6875d05cadcef85ab26228055a2 /lua/telescope/builtin.lua | |
| parent | 2053a2621a56177da34032a055dffe3f7bb384d1 (diff) | |
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 <devries.timothyj@gmail.com>
Diffstat (limited to 'lua/telescope/builtin.lua')
| -rw-r--r-- | lua/telescope/builtin.lua | 39 |
1 files changed, 39 insertions, 0 deletions
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', '<CR>', view_manpage) + map('n', '<CR>', view_manpage) + + return true + end + }):find() +end + return builtin |
