Skip to content

Commit 55916a7

Browse files
committed
feat(picker): cache apropos result to speed up :Telescope man_pages
1 parent 0d8b6ea commit 55916a7

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

lua/telescope/builtin/__internal.lua

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -827,16 +827,24 @@ internal.man_pages = function(opts)
827827
opts.sections = vim.F.if_nil(opts.sections, { "1" })
828828
assert(vim.islist(opts.sections), "sections should be a list")
829829
opts.man_cmd = utils.get_lazy_default(opts.man_cmd, function()
830+
local cache = Path:new(vim.fn.stdpath "cache", "telescope-man-pages")
831+
if cache:exists() and cache:_stat().size > 0 and os.time() - cache:_stat().mtime.sec < 24 * 60 * 60 then
832+
return { "cat", cache.filename }
833+
end
834+
830835
local uname = vim.uv.os_uname()
831836
local sysname = string.lower(uname.sysname)
837+
local cmd
832838
if sysname == "darwin" then
833839
local major_version = tonumber(vim.fn.matchlist(uname.release, [[^\(\d\+\)\..*]])[2]) or 0
834-
return major_version >= 22 and { "apropos", "." } or { "apropos", " " }
840+
cmd = major_version >= 22 and "apropos ." or "apropos ' '"
835841
elseif sysname == "freebsd" then
836-
return { "apropos", "." }
842+
cmd = "apropos ."
837843
else
838-
return { "apropos", "" }
844+
cmd = "apropos ''"
839845
end
846+
847+
return { "sh", "-c", string.format("%s | tee %s", cmd, cache.filename) }
840848
end)
841849
opts.entry_maker = opts.entry_maker or make_entry.gen_from_apropos(opts)
842850
opts.env = { PATH = vim.env.PATH, MANPATH = vim.env.MANPATH }

0 commit comments

Comments
 (0)