@@ -3,65 +3,34 @@ local Select = require("fuzzy.select")
33local util = require (" fuzzy.pickers.util" )
44
55--- @class ManpagesPickerOptions
6+ --- @field command_args ? string[] Override the arguments passed to the command
67
78local M = {}
89
9- local function parse_manpage_entries (raw_output )
10- local entries = {}
11- local entry_map = {}
12- for line in tostring (raw_output or " " ):gmatch (" [^\r\n ]+" ) do
13- local name , section = line :match (" ^%s*([^%s%(,]+)[^%(]*%(([^%)]+)%)" )
14- local entry = nil
15- if name and section then
16- entry = string.format (" %s(%s)" , name , section )
17- else
18- entry = line :match (" ^%s*(%S+)" )
19- end
20- if entry and # entry > 0 and not entry_map [entry ] then
21- entry_map [entry ] = true
22- entries [# entries + 1 ] = entry
23- end
10+ local function parse_manpage_entry (line )
11+ local name , section = tostring (line or " " ):match (" ^%s*([^%s%(,]+)[^%(]*%(([^%)]+)%)" )
12+ if name and section then
13+ return string.format (" %s(%s)" , name , section )
2414 end
25- return entries
26- end
27-
28- local function collect_manpage_entries ()
29- local command_name = util .pick_first_command ({ " apropos" , " man" })
30- if not command_name then
31- return {}
32- end
33- local result = vim .system ({ command_name , " -k" , " ." }, {
34- text = true ,
35- }):wait ()
36- if not result or result .code ~= 0 then
37- return {}
38- end
39- return parse_manpage_entries (result .stdout )
15+ return tostring (line or " " ):match (" ^%s*(%S+)" )
4016end
4117
4218--- Open Manpages picker.
4319--- @param opts ManpagesPickerOptions | nil Picker options for this picker
4420--- @return Picker
4521function M .open_manpages_picker (opts )
22+ local cmd = util .pick_first_command ({ " apropos" , " man" })
4623 opts = util .merge_picker_options ({
47- preview = false ,
24+ command_args = { " -k " , " . " }
4825 }, opts )
4926
5027 local picker = Picker .new (vim .tbl_extend (" force" , {
51- content = function (stream , args )
52- for _ , manpage in ipairs (args .items ) do
53- stream (manpage )
54- end
55- stream (nil )
56- end ,
28+ content = assert (cmd ),
5729 headers = util .build_picker_headers (" Manpages" , opts ),
5830 context = {
59- args = function (_ )
60- return {
61- items = collect_manpage_entries (),
62- }
63- end ,
31+ args = opts .command_args ,
6432 },
33+ stream_map = parse_manpage_entry ,
6534 preview = false ,
6635 actions = {
6736 [" <cr>" ] = Select .action (Select .default_select , Select .first (function (entry )
0 commit comments