41 lines
956 B
Lua
41 lines
956 B
Lua
|
local function join(delimiter, list)
|
||
|
local result = ""
|
||
|
local len = #list
|
||
|
for i, v in ipairs(list) do
|
||
|
result = result .. tostring(v)
|
||
|
if i < len then
|
||
|
result = result .. tostring(delimiter)
|
||
|
end
|
||
|
end
|
||
|
return result
|
||
|
end
|
||
|
|
||
|
local function quoted(str)
|
||
|
local escaped_str = string.gsub(str, '[\\"]', '\\%1')
|
||
|
return '"' .. escaped_str .. '"'
|
||
|
end
|
||
|
|
||
|
local lfs = require("lfs")
|
||
|
|
||
|
return {
|
||
|
cmd = function(cmd)
|
||
|
if type(cmd) == "string" then
|
||
|
cmd = {cmd}
|
||
|
end
|
||
|
|
||
|
local cmd_line = table.concat(cmd, "\n")
|
||
|
for i, v in ipairs(cmd) do
|
||
|
cmd[i] = "\27[32m-> \27[0m" .. string.gsub(cmd[i], "\n", "\n\27[32m-> \27[0m")
|
||
|
end
|
||
|
local print_line = table.concat(cmd, "\n")
|
||
|
print(print_line)
|
||
|
return assert(os.execute("bash -e -c " .. quoted(cmd_line)))
|
||
|
end,
|
||
|
|
||
|
|
||
|
cd = function(path)
|
||
|
print("\27[32m-> \27[0mcd " .. path)
|
||
|
assert(lfs.chdir(path))
|
||
|
end
|
||
|
}
|