diff options
| author | Simon Hauser <Simon-Hauser@outlook.de> | 2020-11-13 21:07:12 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-13 15:07:12 -0500 |
| commit | 76e7fe8cb037e7944dbb13ec34362166d44e625b (patch) | |
| tree | 97987fa49966a47b6b5dc8ec1b79f2ed9bdfd354 /lua/telescope/previewers.lua | |
| parent | 9fad317d0565e4e258d6fdea1279a5ace968549b (diff) | |
fix: Multiple Previewer fixes (#225)
Fixes previews for files beginning with ~/
Previewer will now show directories
Fix if clause with vim.fn.executable
Diffstat (limited to 'lua/telescope/previewers.lua')
| -rw-r--r-- | lua/telescope/previewers.lua | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/lua/telescope/previewers.lua b/lua/telescope/previewers.lua index 0fe2ed2..47b6e0d 100644 --- a/lua/telescope/previewers.lua +++ b/lua/telescope/previewers.lua @@ -21,7 +21,15 @@ Previewer.__index = Previewer local bat_options = {"--style=plain", "--color=always", "--paging=always"} local has_less = (vim.fn.executable('less') == 1) and config.values.use_less +local get_file_stat = function(filename) + return assert(vim.loop.fs_stat(vim.fn.expand(filename))) +end + local bat_maker = function(filename, lnum, start, finish) + if get_file_stat(filename).type == 'directory' then + return { 'ls', '-la' } + end + local command = {"bat"} local theme = os.getenv("BAT_THEME") @@ -46,23 +54,26 @@ local bat_maker = function(filename, lnum, start, finish) end return flatten { - command, bat_options, "--", filename + command, bat_options, "--", vim.fn.expand(filename) } end -- TODO: Add other options for cat to do this better local cat_maker = function(filename, _, _, _) - if vim.fn.executable('file') then - local handle = io.popen('file --mime-type -b ' .. filename) - local mime_type = vim.split(handle:read('*a'), '/')[1] - handle:close() + if get_file_stat(filename).type == 'directory' then + return { 'ls', '-la' } + end + + if 1 == vim.fn.executable('file') then + local output = utils.get_os_command_output('file --mime-type -b ' .. filename) + local mime_type = vim.split(output, '/')[1] if mime_type ~= "text" then return { "echo", "Binary file found. These files cannot be displayed!" } end end return { - "cat", "--", filename + "cat", "--", vim.fn.expand(filename) } end |
