mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-18 11:48:02 -04:00
Preparation for #634.
Won't go through with it yet because it requires some more adjustments, e.g. set can't remain a program, will need to be a shell builtin; in general, programs relying on setenv being global will break.
This commit is contained in:
parent
e285c5875e
commit
b8e189cacd
@ -4,20 +4,23 @@ local fs = require("filesystem")
|
|||||||
local shell = require("shell")
|
local shell = require("shell")
|
||||||
local unicode = require("unicode")
|
local unicode = require("unicode")
|
||||||
|
|
||||||
local env = {
|
local function env()
|
||||||
EDITOR="/bin/edit",
|
-- copy parent env when first requested; easiest way to keep things
|
||||||
HISTSIZE="10",
|
-- like number of env vars trivial (#vars).
|
||||||
HOME="/home",
|
local data = require("process").info().data
|
||||||
IFS=" ",
|
--[[ TODO breaking change; will require set to be a shell built-in and
|
||||||
MANPATH="/usr/man:.",
|
may break other programs relying on setenv being global.
|
||||||
PAGER="/bin/more",
|
if not rawget(data, "vars") then
|
||||||
PATH="/bin:/usr/bin:/home/bin:.",
|
local vars = {}
|
||||||
PS1="$PWD# ",
|
for k, v in pairs(data.vars or {}) do
|
||||||
PWD="/",
|
vars[k] = v
|
||||||
SHELL="/bin/sh",
|
end
|
||||||
TMP="/tmp", -- Deprecated
|
data.vars = vars
|
||||||
TMPDIR="/tmp"
|
end
|
||||||
}
|
--]]
|
||||||
|
data.vars = data.vars or {}
|
||||||
|
return data.vars
|
||||||
|
end
|
||||||
|
|
||||||
os.execute = function(command)
|
os.execute = function(command)
|
||||||
if not command then
|
if not command then
|
||||||
@ -32,23 +35,23 @@ end
|
|||||||
|
|
||||||
function os.getenv(varname)
|
function os.getenv(varname)
|
||||||
if varname == '#' then
|
if varname == '#' then
|
||||||
return #env
|
return #env()
|
||||||
elseif varname ~= nil then
|
elseif varname ~= nil then
|
||||||
return env[varname]
|
return env()[varname]
|
||||||
else
|
else
|
||||||
return env
|
return env()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function os.setenv(varname, value)
|
function os.setenv(varname, value)
|
||||||
checkArg(1, varname, "string", "number")
|
checkArg(1, varname, "string", "number")
|
||||||
if value == nil then
|
if value == nil then
|
||||||
env[varname] = nil
|
env()[varname] = nil
|
||||||
else
|
else
|
||||||
local success, val = pcall(tostring, value)
|
local success, val = pcall(tostring, value)
|
||||||
if success then
|
if success then
|
||||||
env[varname] = val
|
env()[varname] = val
|
||||||
return env[varname]
|
return env()[varname]
|
||||||
else
|
else
|
||||||
return nil, val
|
return nil, val
|
||||||
end
|
end
|
||||||
@ -83,6 +86,19 @@ function os.tmpname()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
os.setenv("EDITOR", "/bin/edit")
|
||||||
|
os.setenv("HISTSIZE", "10")
|
||||||
|
os.setenv("HOME", "/home")
|
||||||
|
os.setenv("IFS", " ")
|
||||||
|
os.setenv("MANPATH", "/usr/man:.")
|
||||||
|
os.setenv("PAGER", "/bin/more")
|
||||||
|
os.setenv("PATH", "/bin:/usr/bin:/home/bin:.")
|
||||||
|
os.setenv("PS1", "$PWD# ")
|
||||||
|
os.setenv("PWD", "/")
|
||||||
|
os.setenv("SHELL", "/bin/sh")
|
||||||
|
os.setenv("TMP", "/tmp") -- Deprecated
|
||||||
|
os.setenv("TMPDIR", "/tmp")
|
||||||
|
|
||||||
if computer.tmpAddress() then
|
if computer.tmpAddress() then
|
||||||
fs.mount(computer.tmpAddress(), os.getenv("TMPDIR") or "/tmp")
|
fs.mount(computer.tmpAddress(), os.getenv("TMPDIR") or "/tmp")
|
||||||
end
|
end
|
Loading…
x
Reference in New Issue
Block a user