diff options
| author | zbq <zhengbaiqiang@gmail.com> | 2022-11-29 05:41:37 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-28 22:41:37 +0100 |
| commit | 3c2e5fb23e9f6ca1aa682ae16bac3319bfe03e38 (patch) | |
| tree | 445402b9012bed7dfa1e3ca38e69dedd2c624e0c | |
| parent | 4d77743a8ec4d19b3c47e0d04f3e88f1a933698e (diff) | |
feat: add configuration to fix encoding of output of find_command in find_files (#2232)
| -rw-r--r-- | doc/telescope.txt | 39 | ||||
| -rw-r--r-- | lua/telescope/builtin/init.lua | 1 | ||||
| -rw-r--r-- | lua/telescope/make_entry.lua | 11 |
3 files changed, 30 insertions, 21 deletions
diff --git a/doc/telescope.txt b/doc/telescope.txt index d2ac210..9c1a97b 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -838,25 +838,26 @@ builtin.find_files({opts}) *telescope.builtin.find_files()* {opts} (table) options to pass to the picker Options: ~ - {cwd} (string) root dir to search from (default: - cwd, use utils.buffer_dir() to - search relative to open buffer) - {find_command} (function|table) cmd to use for the search. Can be - a fn(opts) -> tbl (default: - autodetect) - {follow} (boolean) if true, follows symlinks (i.e. - uses `-L` flag for the `find` - command) - {hidden} (boolean) determines whether to show hidden - files or not (default: false) - {no_ignore} (boolean) show files ignored by .gitignore, - .ignore, etc. (default: false) - {no_ignore_parent} (boolean) show files ignored by .gitignore, - .ignore, etc. in parent dirs. - (default: false) - {search_dirs} (table) directory/directories/files to - search - {search_file} (string) specify a filename to search for + {cwd} (string) root dir to search from (default: + cwd, use utils.buffer_dir() to + search relative to open buffer) + {find_command} (function|table) cmd to use for the search. Can be + a fn(opts) -> tbl (default: + autodetect) + {file_entry_encoding} (string) encoding of output of `find_command` + {follow} (boolean) if true, follows symlinks (i.e. + uses `-L` flag for the `find` + command) + {hidden} (boolean) determines whether to show hidden + files or not (default: false) + {no_ignore} (boolean) show files ignored by .gitignore, + .ignore, etc. (default: false) + {no_ignore_parent} (boolean) show files ignored by .gitignore, + .ignore, etc. in parent dirs. + (default: false) + {search_dirs} (table) directory/directories/files to + search + {search_file} (string) specify a filename to search for builtin.fd() *telescope.builtin.fd()* diff --git a/lua/telescope/builtin/init.lua b/lua/telescope/builtin/init.lua index 23f3e4e..eef35b6 100644 --- a/lua/telescope/builtin/init.lua +++ b/lua/telescope/builtin/init.lua @@ -74,6 +74,7 @@ builtin.grep_string = require_on_exported_call("telescope.builtin.__files").grep ---@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 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 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) diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index 699145c..19e3674 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -192,8 +192,15 @@ do return rawget(t, rawget(lookup_keys, k)) end - return function(line) - return setmetatable({ line }, mt_file_entry) + if opts.file_entry_encoding then + 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 |
