mirror of https://github.com/sharkdp/bat
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
645 B
Lua
22 lines
645 B
Lua
-- Note: this plugin depends on the existence of 'inspect' [1] and 'hexyl' [2]
|
|
--
|
|
-- [1] https://github.com/sharkdp/content_inspector
|
|
-- [2] https://github.com/sharkdp/hexyl
|
|
|
|
function is_binary(path)
|
|
local stream = assert(io.popen("inspect '" .. path .. "'"))
|
|
local output = stream:read('*all')
|
|
stream:close()
|
|
return string.find(output, ": binary\n")
|
|
end
|
|
|
|
function preprocess(path)
|
|
if is_binary(path) then
|
|
tmpfile = os.tmpname()
|
|
os.execute("hexyl --length 1024 --no-position --border=none --no-squeezing '" .. path .. "' > '" .. tmpfile .. "'")
|
|
return tmpfile
|
|
else
|
|
return path
|
|
end
|
|
end
|