break!: remove file_browser from builtins (#1453)
The file_browser now has been fully removed. Please move to github.com/nvim-telescope/telescope-file-browser.nvim for a more featureful extension that replaces the builtin file browser.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
local actions = require "telescope.actions"
|
||||
local action_state = require "telescope.actions.state"
|
||||
local action_set = require "telescope.actions.set"
|
||||
local finders = require "telescope.finders"
|
||||
@@ -10,9 +9,7 @@ local utils = require "telescope.utils"
|
||||
local conf = require("telescope.config").values
|
||||
local log = require "telescope.log"
|
||||
|
||||
local scan = require "plenary.scandir"
|
||||
local Path = require "plenary.path"
|
||||
local os_sep = Path.path.sep
|
||||
|
||||
local flatten = vim.tbl_flatten
|
||||
local filter = vim.tbl_filter
|
||||
@@ -263,142 +260,6 @@ local function prepare_match(entry, kind)
|
||||
return entries
|
||||
end
|
||||
|
||||
files.file_browser = function(opts)
|
||||
vim.api.nvim_err_writeln [[Deprecation notice: file browser will be carved out into a more featureful extension, see:
|
||||
https://github.com/nvim-telescope/telescope-file-browser.nvim]]
|
||||
|
||||
opts = opts or {}
|
||||
|
||||
local is_dir = function(value)
|
||||
return value:sub(-1, -1) == os_sep
|
||||
end
|
||||
|
||||
opts.depth = opts.depth or 1
|
||||
opts.cwd = opts.cwd and vim.fn.expand(opts.cwd) or vim.loop.cwd()
|
||||
opts.new_finder = opts.new_finder
|
||||
or function(path)
|
||||
opts.cwd = path
|
||||
local data = {}
|
||||
|
||||
scan.scan_dir(path, {
|
||||
hidden = opts.hidden or false,
|
||||
add_dirs = true,
|
||||
depth = opts.depth,
|
||||
on_insert = function(entry, typ)
|
||||
table.insert(data, typ == "directory" and (entry .. os_sep) or entry)
|
||||
end,
|
||||
})
|
||||
table.insert(data, 1, ".." .. os_sep)
|
||||
|
||||
local maker = function()
|
||||
local mt = {}
|
||||
mt.cwd = opts.cwd
|
||||
mt.display = function(entry)
|
||||
local hl_group
|
||||
local display = utils.transform_path(opts, entry.value)
|
||||
if is_dir(entry.value) then
|
||||
display = display .. os_sep
|
||||
if not opts.disable_devicons then
|
||||
display = (opts.dir_icon or "") .. " " .. display
|
||||
hl_group = "Default"
|
||||
end
|
||||
else
|
||||
display, hl_group = utils.transform_devicons(entry.value, display, opts.disable_devicons)
|
||||
end
|
||||
|
||||
if hl_group then
|
||||
return display, { { { 1, 3 }, hl_group } }
|
||||
else
|
||||
return display
|
||||
end
|
||||
end
|
||||
|
||||
mt.__index = function(t, k)
|
||||
local raw = rawget(mt, k)
|
||||
if raw then
|
||||
return raw
|
||||
end
|
||||
|
||||
if k == "path" then
|
||||
local retpath = Path:new({ t.cwd, t.value }):absolute()
|
||||
if not vim.loop.fs_access(retpath, "R", nil) then
|
||||
retpath = t.value
|
||||
end
|
||||
if is_dir(t.value) then
|
||||
retpath = retpath .. os_sep
|
||||
end
|
||||
return retpath
|
||||
end
|
||||
|
||||
return rawget(t, rawget({ value = 1 }, k))
|
||||
end
|
||||
|
||||
return function(line)
|
||||
local tbl = { line }
|
||||
tbl.ordinal = Path:new(line):make_relative(opts.cwd)
|
||||
return setmetatable(tbl, mt)
|
||||
end
|
||||
end
|
||||
|
||||
return finders.new_table { results = data, entry_maker = maker() }
|
||||
end
|
||||
|
||||
pickers.new(opts, {
|
||||
prompt_title = "File Browser",
|
||||
finder = opts.new_finder(opts.cwd),
|
||||
previewer = conf.file_previewer(opts),
|
||||
sorter = conf.file_sorter(opts),
|
||||
attach_mappings = function(prompt_bufnr, map)
|
||||
action_set.select:replace_if(function()
|
||||
return is_dir(action_state.get_selected_entry().path)
|
||||
end, function()
|
||||
local new_cwd = vim.fn.expand(action_state.get_selected_entry().path:sub(1, -2))
|
||||
local current_picker = action_state.get_current_picker(prompt_bufnr)
|
||||
current_picker.cwd = new_cwd
|
||||
current_picker:refresh(opts.new_finder(new_cwd), { reset_prompt = true })
|
||||
end)
|
||||
|
||||
local create_new_file = function()
|
||||
local current_picker = action_state.get_current_picker(prompt_bufnr)
|
||||
local file = action_state.get_current_line()
|
||||
if file == "" then
|
||||
print(
|
||||
"To create a new file or directory(add "
|
||||
.. os_sep
|
||||
.. " at the end of file) "
|
||||
.. "write the desired new into the prompt and press <C-e>. "
|
||||
.. "It works for not existing nested input as well."
|
||||
.. "Example: this"
|
||||
.. os_sep
|
||||
.. "is"
|
||||
.. os_sep
|
||||
.. "a"
|
||||
.. os_sep
|
||||
.. "new_file.lua"
|
||||
)
|
||||
return
|
||||
end
|
||||
|
||||
local fpath = current_picker.cwd .. os_sep .. file
|
||||
if not is_dir(fpath) then
|
||||
actions.close(prompt_bufnr)
|
||||
Path:new(fpath):touch { parents = true }
|
||||
vim.cmd(string.format(":e %s", fpath))
|
||||
else
|
||||
Path:new(fpath:sub(1, -2)):mkdir { parents = true }
|
||||
local new_cwd = vim.fn.expand(fpath)
|
||||
current_picker.cwd = new_cwd
|
||||
current_picker:refresh(opts.new_finder(new_cwd), { reset_prompt = true })
|
||||
end
|
||||
end
|
||||
|
||||
map("i", "<C-e>", create_new_file)
|
||||
map("n", "<C-e>", create_new_file)
|
||||
return true
|
||||
end,
|
||||
}):find()
|
||||
end
|
||||
|
||||
-- TODO: finish docs for opts.show_line
|
||||
files.treesitter = function(opts)
|
||||
opts.show_line = utils.get_default(opts.show_line, true)
|
||||
|
||||
Reference in New Issue
Block a user