Clean io mode for sh.lua

Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
Łukasz Magiera 2015-02-13 19:49:13 +01:00
parent 82e57b507b
commit 4cedbb41e7
No known key found for this signature in database
GPG Key ID: DAF1D53BBD4D4790

View File

@ -253,6 +253,23 @@ if #args == 0 and (io.input() == io.stdin or options.i) and not options.c then
end
end
end
elseif #args == 0 and (io.input() ~= io.stdin) then
while true do
io.write(expand(os.getenv("PS1") or "$ "))
local command = io.read("*l")
if not command then
io:write("exit\n")
end
command = text.trim(command)
if command == "exit" then
return
elseif command ~= "" then
local result, reason = os.execute(command)
if not result then
io.stderr:write((tostring(reason) or "unknown error").. "\n")
end
end
end
else
-- execute command.
local result = table.pack(execute(...))