Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: folder_browser with more filetypes #73

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/telescope-file-browser.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ fb_picker.file_browser({opts}) *fb_picker.file_browser()*
{respect_gitignore} (boolean) induces slow-down w/ plenary finder
(default: false, true if `fd`
available)
{types} (table) table incl. {"file", "directory"},
(default: { "directory" })
{browse_files} (function) custom override for the file browser
(default: |fb_finders.browse_files|)
{browse_folders} (function) custom override for the folder browser
Expand Down
28 changes: 26 additions & 2 deletions lua/telescope/_extensions/file_browser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,39 @@ local pconf = {
action_set.select:replace_if(function()
-- test whether selected entry is directory
local entry = action_state.get_selected_entry()
return entry and entry.Path:is_dir()
local current_picker = action_state.get_current_picker(prompt_bufnr)
local finder = current_picker.finder
return entry and (entry.Path:is_dir() or finder.files == false)
end, function()
local path = vim.loop.fs_realpath(action_state.get_selected_entry().path)
local entry = action_state.get_selected_entry()
local is_dir = entry.Path:is_dir()
local path = is_dir and entry.Path:absolute() or entry.Path:parent():absolute()
local current_picker = action_state.get_current_picker(prompt_bufnr)
local finder = current_picker.finder

finder.files = true
finder.path = path
fb_utils.redraw_border_title(current_picker)
current_picker:refresh(finder, { reset_prompt = true, multi = current_picker._multi })
if not is_dir then
vim.schedule(function()
local index = 1
for e in current_picker.manager:iter() do
if index > current_picker.max_results then
break
end
if e.value == entry.value then
vim.schedule(function()
vim.schedule(function()
current_picker:set_selection(current_picker:get_row(index))
end)
end)
break
end
index = index + 1
end
end)
end
end)
return true
end,
Expand Down
10 changes: 8 additions & 2 deletions lua/telescope/_extensions/file_browser/finders.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ fb_finders.browse_folders = function(opts)
local cwd = opts.cwd_to_path and opts.path or opts.cwd
local entry_maker = opts.entry_maker { cwd = cwd }
if has_fd then
local args = { "-t", "d", "-a" }
local args = { "-a" }
if opts.hidden then
table.insert(args, "-H")
end
for _, type_ in ipairs(opts.types) do
table.insert(args, "-t")
table.insert(args, type_)
end
if opts.respect_gitignore == false then
table.insert(args, "--no-ignore-vcs")
end
Expand All @@ -100,7 +104,8 @@ fb_finders.browse_folders = function(opts)
else
local data = scan.scan_dir(opts.cwd, {
hidden = opts.hidden,
only_dirs = true,
add_dirs = vim.tbl_contains(opts.types, "directory"),
only_dirs = not vim.tbl_contains(opts.types, "file"),
respect_gitignore = opts.respect_gitignore,
})
table.insert(data, 1, opts.cwd)
Expand Down Expand Up @@ -135,6 +140,7 @@ fb_finders.finder = function(opts)
files = vim.F.if_nil(opts.files, true), -- file or folders mode
grouped = vim.F.if_nil(opts.grouped, false),
-- ensure we forward make_entry opts adequately
types = vim.F.if_nil(opts.types, { "directory" }),
entry_maker = vim.F.if_nil(opts.entry_maker, function(local_opts)
return fb_make_entry(vim.tbl_extend("force", opts, local_opts))
end),
Expand Down
1 change: 1 addition & 0 deletions lua/telescope/_extensions/file_browser/picker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ local fb_picker = {}
---@field dir_icon string: change the icon for a directory (default: )
---@field hidden boolean: determines whether to show hidden files or not (default: false)
---@field respect_gitignore boolean: induces slow-down w/ plenary finder (default: false, true if `fd` available)
---@field types table: table incl. {"file", "directory"}, (default: { "directory" })
---@field browse_files function: custom override for the file browser (default: |fb_finders.browse_files|)
---@field browse_folders function: custom override for the folder browser (default: |fb_finders.browse_folders|)
fb_picker.file_browser = function(opts)
Expand Down