Add directory-scoped Telescope pickers and smart folding

This commit is contained in:
Joshua Bell 2026-01-29 00:38:44 -06:00
parent fedaece719
commit 7affddc1b8
3 changed files with 101 additions and 20 deletions

View file

@ -176,4 +176,28 @@ function M.fnZero()
return 0
end
--- Opens telescope file browser to pick a directory, then calls callback with the selected path.
--- Starts at the current buffer's parent directory for quick access.
---@param callback fun(dir: string): nil Function to call with selected directory path
function M.pick_directory_then(callback)
local actions = require("telescope.actions")
local action_state = require("telescope.actions.state")
require("telescope").extensions.file_browser.file_browser({
path = vim.fn.expand("%:p:h"),
select_buffer = true,
files = false, -- Only show directories
depth = false,
attach_mappings = function(prompt_bufnr, _)
actions.select_default:replace(function()
local entry = action_state.get_selected_entry()
local dir = entry and entry.path or vim.fn.expand("%:p:h")
actions.close(prompt_bufnr)
callback(dir)
end)
return true
end,
})
end
return M