Cat will no longer display binary files (#224)

This commit is contained in:
Simon Hauser
2020-11-06 01:53:57 +01:00
committed by GitHub
parent 1f3110bf54
commit d8befe2437

View File

@@ -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
}