feat: Allow filtering for oldfiles and buffers (#2353)
This commit is contained in:
@@ -1214,6 +1214,8 @@ builtin.oldfiles({opts}) *telescope.builtin.oldfiles()*
|
|||||||
{opts} (table) options to pass to the picker
|
{opts} (table) options to pass to the picker
|
||||||
|
|
||||||
Options: ~
|
Options: ~
|
||||||
|
{cwd} (string) specify a working directory to filter oldfiles
|
||||||
|
by
|
||||||
{only_cwd} (boolean) show only files in the cwd (default: false)
|
{only_cwd} (boolean) show only files in the cwd (default: false)
|
||||||
{cwd_only} (boolean) alias for only_cwd
|
{cwd_only} (boolean) alias for only_cwd
|
||||||
|
|
||||||
@@ -1301,6 +1303,8 @@ builtin.buffers({opts}) *telescope.builtin.buffers()*
|
|||||||
{opts} (table) options to pass to the picker
|
{opts} (table) options to pass to the picker
|
||||||
|
|
||||||
Options: ~
|
Options: ~
|
||||||
|
{cwd} (string) specify a working directory to
|
||||||
|
filter buffers list by
|
||||||
{show_all_buffers} (boolean) if true, show all buffers,
|
{show_all_buffers} (boolean) if true, show all buffers,
|
||||||
including unloaded buffers
|
including unloaded buffers
|
||||||
(default: true)
|
(default: true)
|
||||||
|
|||||||
@@ -523,8 +523,9 @@ internal.oldfiles = function(opts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if opts.cwd_only then
|
if opts.cwd_only or opts.cwd then
|
||||||
local cwd = vim.loop.cwd() .. utils.get_separator()
|
local cwd = opts.cwd_only and vim.loop.cwd() or opts.cwd
|
||||||
|
cwd = cwd .. utils.get_separator()
|
||||||
cwd = cwd:gsub([[\]], [[\\]])
|
cwd = cwd:gsub([[\]], [[\\]])
|
||||||
results = vim.tbl_filter(function(file)
|
results = vim.tbl_filter(function(file)
|
||||||
return vim.fn.matchstrpos(file, cwd)[2] ~= -1
|
return vim.fn.matchstrpos(file, cwd)[2] ~= -1
|
||||||
@@ -878,6 +879,9 @@ internal.buffers = function(opts)
|
|||||||
if opts.cwd_only and not string.find(vim.api.nvim_buf_get_name(b), vim.loop.cwd(), 1, true) then
|
if opts.cwd_only and not string.find(vim.api.nvim_buf_get_name(b), vim.loop.cwd(), 1, true) then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
if not opts.cwd_only and opts.cwd and not string.find(vim.api.nvim_buf_get_name(b), opts.cwd, 1, true) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
return true
|
return true
|
||||||
end, vim.api.nvim_list_bufs())
|
end, vim.api.nvim_list_bufs())
|
||||||
if not next(bufnrs) then
|
if not next(bufnrs) then
|
||||||
|
|||||||
@@ -265,6 +265,7 @@ builtin.loclist = require_on_exported_call("telescope.builtin.__internal").locli
|
|||||||
|
|
||||||
--- Lists previously open files, opens on `<cr>`
|
--- Lists previously open files, opens on `<cr>`
|
||||||
---@param opts table: options to pass to the picker
|
---@param opts table: options to pass to the picker
|
||||||
|
---@field cwd string: specify a working directory to filter oldfiles by
|
||||||
---@field only_cwd boolean: show only files in the cwd (default: false)
|
---@field only_cwd boolean: show only files in the cwd (default: false)
|
||||||
---@field cwd_only boolean: alias for only_cwd
|
---@field cwd_only boolean: alias for only_cwd
|
||||||
builtin.oldfiles = require_on_exported_call("telescope.builtin.__internal").oldfiles
|
builtin.oldfiles = require_on_exported_call("telescope.builtin.__internal").oldfiles
|
||||||
@@ -305,6 +306,7 @@ builtin.reloader = require_on_exported_call("telescope.builtin.__internal").relo
|
|||||||
|
|
||||||
--- Lists open buffers in current neovim instance, opens selected buffer on `<cr>`
|
--- Lists open buffers in current neovim instance, opens selected buffer on `<cr>`
|
||||||
---@param opts table: options to pass to the picker
|
---@param opts table: options to pass to the picker
|
||||||
|
---@field cwd string: specify a working directory to filter buffers list by
|
||||||
---@field show_all_buffers boolean: if true, show all buffers, including unloaded buffers (default: true)
|
---@field show_all_buffers boolean: if true, show all buffers, including unloaded buffers (default: true)
|
||||||
---@field ignore_current_buffer boolean: if true, don't show the current buffer in the list (default: false)
|
---@field ignore_current_buffer boolean: if true, don't show the current buffer in the list (default: false)
|
||||||
---@field only_cwd boolean: if true, only show buffers in the current working directory (default: false)
|
---@field only_cwd boolean: if true, only show buffers in the current working directory (default: false)
|
||||||
|
|||||||
Reference in New Issue
Block a user