summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorSimon Hauser <Simon-Hauser@outlook.de>2020-11-06 01:53:57 +0100
committerGitHub <noreply@github.com>2020-11-05 19:53:57 -0500
commitd8befe243752bd1b295d84e35a53d16a0de55aa9 (patch)
treeb64c82cb382f5d9e313f8516ab83603584635a1a /lua
parent1f3110bf54877b975956e42911e05d517d8f4993 (diff)
Cat will no longer display binary files (#224)
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
}