mirror of
https://github.com/sharkdp/bat.git
synced 2024-11-26 17:53:54 +01:00
21 lines
561 B
Lua
21 lines
561 B
Lua
|
function tempdir()
|
||
|
local stream = assert(io.popen('mktemp --directory'))
|
||
|
local output = stream:read('*all')
|
||
|
stream:close()
|
||
|
return string.gsub(output, "\n", "")
|
||
|
end
|
||
|
|
||
|
function preprocess(path)
|
||
|
prefix = string.match(path, '^(.*)%.gz$')
|
||
|
if prefix then
|
||
|
local temp_directory = tempdir()
|
||
|
local new_path = temp_directory .. "/" .. prefix
|
||
|
|
||
|
-- TODO: how to prevent shell injection bugs?
|
||
|
os.execute("gunzip < '" .. path .. "' > '" .. new_path .. "'")
|
||
|
|
||
|
return new_path
|
||
|
else
|
||
|
return path
|
||
|
end
|
||
|
end
|