34 lines
921 B
Lua
34 lines
921 B
Lua
-- Minimal luash helper functions
|
|
|
|
-- Local environment variable storage
|
|
local env_vars = {}
|
|
|
|
-- Environment variable access
|
|
function env_get(name)
|
|
-- Check local storage first, then system environment
|
|
return env_vars[name] or os.getenv(name) or ""
|
|
end
|
|
|
|
function env_set(name, value)
|
|
-- Store locally for this session
|
|
env_vars[name] = tostring(value)
|
|
-- Also try to set for subprocesses with proper quoting
|
|
local quoted_value = "'" .. tostring(value):gsub("'", "'\"'\"'") .. "'"
|
|
os.execute("export " .. name .. "=" .. quoted_value)
|
|
end
|
|
|
|
-- Shell command execution
|
|
function shell(command)
|
|
local handle = io.popen(command, "r")
|
|
if not handle then return "" end
|
|
local output = handle:read("*a")
|
|
handle:close()
|
|
-- Remove trailing newlines
|
|
return (output or ""):gsub("[\r\n]+$", "")
|
|
end
|
|
|
|
-- Interactive command execution (shows output directly)
|
|
function run(command)
|
|
return os.execute(command)
|
|
end
|