Files
Halyde/lib/shell.lua
T
WahPlus ae1652b1b9 Rename /halyde/shell to /halyde/scripts
The reason is because there will have to be a place to put scripts that
are not apps.
2025-10-30 13:15:04 +02:00

43 lines
1.1 KiB
Lua

local filesystem = require("filesystem")
-- get a list of installed shells
local shellDir = filesystem.list("/halyde/scripts/") -- HACK: /halyde/scripts features more than just shells!
local shells = {}
for i=1,#shellDir do
table.insert(shells,string.match(shellDir[i],"([^/]+)%.lua$"))
end
-- locate the shell
local tasks = tsched.getTasks()
-- print(tasks)
local pid = tsched.getCurrentTask().id
local function taskFromPID(pid)
checkArg(1,pid,"number")
for i=1,#tasks do
if tasks[i] and tasks[i].id==pid then
return tasks[i]
end
end
end
local shellProcess
while true do
local task = taskFromPID(pid)
if not task then
error("parent shell task doesn't exist (ID="..pid..")")
end
if table.find(shells,task.name) then
shellProcess = task
break
end
pid = task.parent
if not pid then
error("could not find parent shell task")
end
end
if not shellProcess then error("could not locate shell task") end
-- get the shell object from the process
-- print("Process ID: "..shellProcess.id)
-- print(ipc.shared[shellProcess.id].shell)
return ipc.shared[shellProcess.id].shell