summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorSvetlozar Iliev <svetlozar321@gmail.com>2023-01-30 19:09:29 +0200
committerGitHub <noreply@github.com>2023-01-30 18:09:29 +0100
commit5dfd807771dbd68b1b776e489c043337baccf638 (patch)
treef935a509aba028e7c14786b4a96c341df6a720c2 /lua
parentd5f6c0911d6066397f1757c6b55a8bd6851bd6dc (diff)
feat: Allow filtering for oldfiles and buffers (#2353)
Diffstat (limited to 'lua')
-rw-r--r--lua/telescope/builtin/__internal.lua8
-rw-r--r--lua/telescope/builtin/init.lua2
2 files changed, 8 insertions, 2 deletions
diff --git a/lua/telescope/builtin/__internal.lua b/lua/telescope/builtin/__internal.lua
index 613643b..e1b6ce3 100644
--- a/lua/telescope/builtin/__internal.lua
+++ b/lua/telescope/builtin/__internal.lua
@@ -523,8 +523,9 @@ internal.oldfiles = function(opts)
end
end
- if opts.cwd_only then
- local cwd = vim.loop.cwd() .. utils.get_separator()
+ if opts.cwd_only or opts.cwd then
+ local cwd = opts.cwd_only and vim.loop.cwd() or opts.cwd
+ cwd = cwd .. utils.get_separator()
cwd = cwd:gsub([[\]], [[\\]])
results = vim.tbl_filter(function(file)
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
return false
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
end, vim.api.nvim_list_bufs())
if not next(bufnrs) then
diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua
index 3036820..65a8cac 100644
--- a/lua/telescope/builtin/init.lua
+++ b/lua/telescope/builtin/init.lua
@@ -265,6 +265,7 @@ builtin.loclist = require_on_exported_call("telescope.builtin.__internal").locli
--- Lists previously open files, opens on `<cr>`
---@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 cwd_only boolean: alias for only_cwd
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>`
---@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 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)