summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua')
-rw-r--r--lua/telescope/previewers.lua11
1 files changed, 10 insertions, 1 deletions
diff --git a/lua/telescope/previewers.lua b/lua/telescope/previewers.lua
index 8925a9e..0fe2ed2 100644
--- a/lua/telescope/previewers.lua
+++ b/lua/telescope/previewers.lua
@@ -51,7 +51,16 @@ local bat_maker = function(filename, lnum, start, finish)
end
-- TODO: Add other options for cat to do this better
-local cat_maker = function(filename, lnum, start, finish)
+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 mime_type ~= "text" then
+ return { "echo", "Binary file found. These files cannot be displayed!" }
+ end
+ end
+
return {
"cat", "--", filename
}