neonucleus/data/OpenOS/bin/source.lua
IonutParau 687cfebd00 testing version of LuaBIOS and OpenOS
people were having issues getting them to work so now we promote consistency
2025-06-28 20:41:49 +02:00

37 lines
883 B
Lua

local shell = require("shell")
local process = require("process")
local args, options = shell.parse(...)
if #args ~= 1 then
io.stderr:write("specify a single file to source\n");
return 1
end
local file, open_reason = io.open(args[1], "r")
if not file then
if not options.q then
io.stderr:write(string.format("could not source %s because: %s\n", args[1], open_reason));
end
return 1
end
local lines = file:lines()
while true do
local line = lines()
if not line then
break
end
local current_data = process.info().data
local source_proc = process.load((assert(os.getenv("SHELL"), "no $SHELL set")))
local source_data = process.list[source_proc].data
source_data.aliases = current_data.aliases -- hacks to propogate sub shell env changes
source_data.vars = current_data.vars
process.internal.continue(source_proc, _ENV, line)
end
file:close()