You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.4 KiB
Lua

3 years ago
local core = require "fzf-lua.core"
local config = require "fzf-lua.config"
local M = {}
M.oldfiles = function(opts)
opts = config.normalize_opts(opts, config.globals.oldfiles)
if not opts then return end
3 years ago
local current_buffer = vim.api.nvim_get_current_buf()
local current_file = vim.api.nvim_buf_get_name(current_buffer)
local results = {}
if opts.include_current_session then
for _, buffer in ipairs(vim.split(vim.fn.execute(':buffers! t'), "\n")) do
local match = tonumber(string.match(buffer, '%s*(%d+)'))
if match then
local file = vim.api.nvim_buf_get_name(match)
if vim.loop.fs_stat(file) and match ~= current_buffer then
table.insert(results, file)
end
end
end
end
for _, file in ipairs(vim.v.oldfiles) do
if vim.loop.fs_stat(file) and not vim.tbl_contains(results, file) and file ~= current_file then
table.insert(results, file)
end
end
local contents = function (cb)
3 years ago
for _, x in ipairs(results) do
x = core.make_entry_file(opts, x)
if x then
cb(x, function(err)
if err then return end
-- close the pipe to fzf, this
-- removes the loading indicator in fzf
cb(nil, function() end)
end)
end
3 years ago
end
cb(nil)
3 years ago
end
opts = core.set_header(opts, 2)
return core.fzf_files(opts, contents)
3 years ago
end
return M