|
|
|
@ -78,16 +78,32 @@ function M.sk_escape(str)
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- TODO: why does `file --dereference --mime` return
|
|
|
|
|
-- wrong result for some lua files ('charset=binary')?
|
|
|
|
|
M.file_is_binary = function(filepath)
|
|
|
|
|
filepath = vim.fn.expand(filepath)
|
|
|
|
|
if vim.fn.executable("file") ~= 1 or
|
|
|
|
|
not vim.loop.fs_stat(filepath) then
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
local out = M.io_system("file --dereference --mime " .. filepath)
|
|
|
|
|
local out = M.io_system("file --dereference --mime " ..
|
|
|
|
|
vim.fn.shellescape(filepath))
|
|
|
|
|
return out:match("charset=binary") ~= nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
M.perl_file_is_binary = function(filepath)
|
|
|
|
|
filepath = vim.fn.expand(filepath)
|
|
|
|
|
if vim.fn.executable("perl") ~= 1 or
|
|
|
|
|
not vim.loop.fs_stat(filepath) then
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
-- can also use '-T' to test for text files
|
|
|
|
|
-- `perldoc -f -x` to learn more about '-B|-T'
|
|
|
|
|
M.io_system("perl -E 'exit((-B $ARGV[0])?0:1);' " ..
|
|
|
|
|
vim.fn.shellescape(filepath))
|
|
|
|
|
return not M.shell_error()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
M.read_file = function(filepath)
|
|
|
|
|
local fd = vim.loop.fs_open(filepath, "r", 438)
|
|
|
|
|
if fd == nil then return '' end
|
|
|
|
|