Files
2026-04-30 15:09:56 +00:00

1 line
1.9 KiB
Lua

local a=import("filesystem")local b=import("json")local c,d,e=a.open("/halyde/config/shell.json","r"),"",nil;repeat e=c:read(math.huge)d=d..(e or"")until not e;c:close()local b=b.decode(d)import("/halyde/core/termlib.lua")local c=import("event")local c=import("component")local c=c.gpu;_G.shell={}_G.shell.workingDirectory=b["defaultWorkingDirectory"]_G.shell.aliases=b["aliases"]local function d(a,...)cormgr.loadCoroutine(a,...)local a=#cormgr.corList;local b=cormgr.corList[#cormgr.corList]repeat coroutine.yield()until cormgr.corList[a]~=b end;function _G.shell.run(c)checkArg(1,c,"string")if shell.aliases[c:match("[^ ]+")]then local a,a=c:find("[^ ]+")c=shell.aliases[c:match("[^ ]+")]..c:sub(a+1)end;local c,e,f,g=c:gmatch("[^ ]+"),nil,{},c;while true do e=c()if not e then break end;if e:find('"')then local a=g:find('"')local b=e:sub(1,e:find('"')-1)if b and b~=""then table.insert(f,b)end;g=g:sub(a+1)if g:find('"')then table.insert(f,g:sub(1,g:find('"')-1))g=g:sub(g:find('"')+1)c=g:gmatch('[^ ]+')else print("\27[91mmalformed shell command")return end else table.insert(f,e)end end;local b=table.copy(b.path)table.insert(b,shell.workingDirectory)if not f[1]then return end;if a.exists(f[1])and not a.isDirectory(f[1])then local a=f[1]table.remove(f,1)d(a,table.unpack(f))return end;for b,b in pairs(b)do if a.exists(b..f[1])and not a.isDirectory(b..f[1])then local a=a.concat(b,f[1])table.remove(f,1)d(a,table.unpack(f))return else local c=a.list(b)or{}for c,c in pairs(c)do if f[1]==c:match("(.+)%.[^%.]+$")and not a.isDirectory(b..c)then table.remove(f,1)d(b..c,table.unpack(f))return end end end end;print("No such file or command: "..f[1])end;print(b["startupMessage"]:format(_OSVERSION,b.splashMessages[math.random(1,#b.splashMessages)]))while true do coroutine.yield()if shell.workingDirectory:sub(-1,-1)~="/"then shell.workingDirectory=shell.workingDirectory.."/"end;local a=read("shell",b.prompt:format(shell.workingDirectory))shell.run(a)c.freeAllBuffers()end