feat: add configuration to fix encoding of output of find_command in find_files (#2232)

This commit is contained in:
zbq
2022-11-29 05:41:37 +08:00
committed by GitHub
parent 4d77743a8e
commit 3c2e5fb23e
3 changed files with 30 additions and 21 deletions

View File

@@ -838,25 +838,26 @@ builtin.find_files({opts}) *telescope.builtin.find_files()*
{opts} (table) options to pass to the picker {opts} (table) options to pass to the picker
Options: ~ Options: ~
{cwd} (string) root dir to search from (default: {cwd} (string) root dir to search from (default:
cwd, use utils.buffer_dir() to cwd, use utils.buffer_dir() to
search relative to open buffer) search relative to open buffer)
{find_command} (function|table) cmd to use for the search. Can be {find_command} (function|table) cmd to use for the search. Can be
a fn(opts) -> tbl (default: a fn(opts) -> tbl (default:
autodetect) autodetect)
{follow} (boolean) if true, follows symlinks (i.e. {file_entry_encoding} (string) encoding of output of `find_command`
uses `-L` flag for the `find` {follow} (boolean) if true, follows symlinks (i.e.
command) uses `-L` flag for the `find`
{hidden} (boolean) determines whether to show hidden command)
files or not (default: false) {hidden} (boolean) determines whether to show hidden
{no_ignore} (boolean) show files ignored by .gitignore, files or not (default: false)
.ignore, etc. (default: false) {no_ignore} (boolean) show files ignored by .gitignore,
{no_ignore_parent} (boolean) show files ignored by .gitignore, .ignore, etc. (default: false)
.ignore, etc. in parent dirs. {no_ignore_parent} (boolean) show files ignored by .gitignore,
(default: false) .ignore, etc. in parent dirs.
{search_dirs} (table) directory/directories/files to (default: false)
search {search_dirs} (table) directory/directories/files to
{search_file} (string) specify a filename to search for search
{search_file} (string) specify a filename to search for
builtin.fd() *telescope.builtin.fd()* builtin.fd() *telescope.builtin.fd()*

View File

@@ -74,6 +74,7 @@ builtin.grep_string = require_on_exported_call("telescope.builtin.__files").grep
---@param opts table: options to pass to the picker ---@param opts table: options to pass to the picker
---@field cwd string: root dir to search from (default: cwd, use utils.buffer_dir() to search relative to open buffer) ---@field cwd string: root dir to search from (default: cwd, use utils.buffer_dir() to search relative to open buffer)
---@field find_command function|table: cmd to use for the search. Can be a fn(opts) -> tbl (default: autodetect) ---@field find_command function|table: cmd to use for the search. Can be a fn(opts) -> tbl (default: autodetect)
---@field file_entry_encoding string: encoding of output of `find_command`
---@field follow boolean: if true, follows symlinks (i.e. uses `-L` flag for the `find` command) ---@field follow boolean: if true, follows symlinks (i.e. uses `-L` flag for the `find` command)
---@field hidden boolean: determines whether to show hidden files or not (default: false) ---@field hidden boolean: determines whether to show hidden files or not (default: false)
---@field no_ignore boolean: show files ignored by .gitignore, .ignore, etc. (default: false) ---@field no_ignore boolean: show files ignored by .gitignore, .ignore, etc. (default: false)

View File

@@ -192,8 +192,15 @@ do
return rawget(t, rawget(lookup_keys, k)) return rawget(t, rawget(lookup_keys, k))
end end
return function(line) if opts.file_entry_encoding then
return setmetatable({ line }, mt_file_entry) return function(line)
line = vim.iconv(line, opts.file_entry_encoding, "utf8")
return setmetatable({ line }, mt_file_entry)
end
else
return function(line)
return setmetatable({ line }, mt_file_entry)
end
end end
end end
end end