forked from Hyperion/HyperionOS
2 lines
25 KiB
Plaintext
2 lines
25 KiB
Plaintext
syscall.open("/dev/tty/1","r")syscall.open("/dev/tty/1","w")syscall.open("/dev/null","w")local a,b=xpcall(function()local c=require("fs")syscall.devctl(1,"clear")syscall.devctl(1,"sfgc",0xFFFFFF)syscall.devctl(1,"spos",1,1)print("HyperionOS hysh Shell")local d=(syscall.getUsername()or"Unknown").."@"..(syscall.getHostname()or"Unknown")local e={}local f=false;syscall.setEnviron("SHELL","hysh")syscall.setEnviron("PATH","/bin/")local g=syscall.getEnviron("HOME")if g and g~=""then local h=pcall(syscall.chdir,g)if not h then syscall.chdir("/")end else syscall.chdir("/")end;local i=""local j={0xFFFFFF,0xFF0000,0x00FF00,0x0000FF,0x00FFFF,0xFF00FF,0xFFFF00,0xFF6D00,0x6DFF55,0x24FFFF,0x924900,0x6D6D55,0xDBDBAA,0x6D00FF,0xB6FF00,0x000000}for k=1,16 do syscall.devctl(1,"sbgc",j[k])printInline(" ")end;print("\n")syscall.sigcatch(function(l)if l==1 then f=true end end)local function m(n)if not n or n==""then return syscall.getcwd()end;if n:sub(1,1)~="/"then n=syscall.getcwd().."/"..n end;local o={}for p in n:gmatch("[^/]+")do if p==".."then if#o>0 then table.remove(o)end elseif p~="."then table.insert(o,p)end end;return"/"..table.concat(o,"/")end;local function q(n)n=n:gsub("/$","")return n:match("([^/]+)$")or n end;local function r(n)n=n:gsub("/$","")local s=n:match("^(.*)/[^/]+$")if not s then return"."end;if s==""then return"/"end;return s end;local function t(u)local v={}while true do local h,w=pcall(syscall.read,u,65536)if not h or not w or w==""then break end;v[#v+1]=w end;return table.concat(v)end;local function x(y)local h,u=pcall(syscall.open,y,"r")if not h then return nil,u end;local z=t(u)pcall(syscall.close,u)return z end;local function A(y,z)local h,u=pcall(syscall.open,y,"w")if not h then return false,u end;pcall(syscall.write,u,z)pcall(syscall.close,u)return true end;local function B(C,D,E)local F={}local G={}E=E or{}local k=1;while k<=#C do local H=C[k]if H=="--"then for I=k+1,#C do G[#G+1]=C[I]end;break elseif H:sub(1,2)=="--"then local J=H:sub(3)if E[J]~=nil then F[J]=true else F["_unknown"]=H end elseif H:sub(1,1)=="-"and#H>1 then for K=2,#H do local L=H:sub(K,K)if D:find(L,1,true)then F[L]=true else F["_unknown"]="-"..L end end else G[#G+1]=H end;k=k+1 end;return F,G end;local function M(N,O)local P=1;while P<=#N do local Q=N:find("\n",P,true)if Q then O(N:sub(P,Q-1))P=Q+1 else O(N:sub(P))break end end end;local function R(N)local S={}M(N,function(T)S[#S+1]=T end)return S end;local function U(V,W)local z,X=x(V)if not z then return false,X end;local h,Y=A(W,z)if not h then return false,Y end;return true end;local function Z(y)local v=syscall.type(y)if v=="directory"then local h,_=pcall(syscall.listdir,y)if h then for a0,a1 in ipairs(_)do Z(y:gsub("/$","").."/"..a1)end end end;if v then pcall(syscall.remove,y)end end;local function a2(V,W)pcall(syscall.mkdir,W)local h,_=pcall(syscall.listdir,V)if not h then return end;for a0,a1 in ipairs(_)do local a3=V:gsub("/$","").."/"..a1;local s=W:gsub("/$","").."/"..a1;local v=syscall.type(a3)if v=="directory"then a2(a3,s)elseif v=="file"then U(a3,s)elseif v=="symlink"then local a4,a5=pcall(syscall.readlink,a3)if a4 then pcall(syscall.remove,s)pcall(syscall.symlink,a5,s)end end end end;local a6={}a6.cd=function(y)local a7=syscall.getcwd()local a8=y or""if a8=="-"then if i==""then print("hysh: cd: no previous directory")return end;print(i)local a9=i;i=a7;syscall.chdir(a9)return end;local aa=m(a8)if aa:sub(-1)~="/"then aa=aa.."/"end;if not c.isDir(aa)then print("hysh: cd: "..a8 ..": No such directory")return end;i=a7;syscall.chdir(aa)end;a6.exit=function(ab)syscall.exit(tonumber(ab)or 0)end;a6.echo=function(...)local G={...}local ac=false;local ad=1;if G[1]=="-n"then ac=true;ad=2 end;local ae=table.concat(G," ",ad)if ac then printInline(ae)else print(ae)end end;a6.pwd=function()print(syscall.getcwd())end;a6["true"]=function()end;a6["false"]=function()end;a6.sleep=function(...)local G={...}if#G==0 then print("sleep: missing operand")return end;local af=0;for a0,ag in ipairs(G)do local ac,ah=ag:match("^([%d%.]+)([smhd]?)$")if not ac then print("sleep: invalid time '"..ag.."'")return end;ac=tonumber(ac)if ah=="m"then ac=ac*60 elseif ah=="h"then ac=ac*3600 elseif ah=="d"then ac=ac*86400 end;af=af+ac end;sleep(af)end;a6.clear=function()syscall.devctl(1,"clear")syscall.devctl(1,"sfgc",0xFFFFFF)syscall.devctl(1,"spos",1,1)end;a6.whoami=function()print(syscall.getUsername()or"unknown")end;a6.hostname=function(...)local G={...}if#G==0 then print(syscall.getHostname()or"unknown")else local h,X=pcall(syscall.setHostname,G[1])if not h then print("hostname: "..tostring(X))end end end;a6.uname=function(...)local F,a0=B({...},"asnrm")local ai=F.a;local o={}local aj={}for ak in string.gmatch(syscall.version(),"%S+")do table.insert(aj,ak)end;if ai or F.s or not F.s and not F.n and not F.r and not F.m then o[#o+1]=aj[1]end;if ai or F.n then o[#o+1]=syscall.getHostname()or"hyperion"end;if ai or F.r then o[#o+1]=aj[2]end;if ai or F.m then o[#o+1]="virtual"end;print(table.concat(o," "))end;a6.printenv=function(...)local G={...}local al={"PATH","HOME","USER","SHELL","TERM","HOSTNAME","PWD","OLDPWD","LANG","TZ","EDITOR"}if#G==0 then for a0,K in ipairs(al)do local h,H=pcall(syscall.getEnviron,K)if h and H then print(K.."="..H)end end else for a0,K in ipairs(G)do local h,H=pcall(syscall.getEnviron,K)if h and H then print(H)end end end end;a6.env=function(...)local G={...}local k=1;while k<=#G and G[k]:match("^[%w_]+=")do local K,H=G[k]:match("^([^=]+)=(.*)")pcall(syscall.setEnviron,K,H)k=k+1 end;if k>#G then a6.printenv()end end;a6.touch=function(...)local a0,G=B({...},"amc")if#G==0 then print("touch: missing operand")return end;for a0,ag in ipairs(G)do local y=m(ag)if not syscall.exists(y)then local h,u=pcall(syscall.open,y,"w")if h then pcall(syscall.close,u)else print("touch: cannot create '"..ag.."': "..tostring(u))end end end end;a6.mkdir=function(...)local F,G=B({...},"p")if#G==0 then print("mkdir: missing operand")return end;for a0,ag in ipairs(G)do local y=m(ag)if y:sub(-1)~="/"then y=y.."/"end;if c.isDir(y)then print("mkdir: cannot create '"..ag.."': Directory exists")return end;local h,X=pcall(syscall.mkdir,y)if not h then print("mkdir: cannot create '"..ag.."': "..tostring(X))end end end;a6.rm=function(...)local F,G=B({...},"rRf")if#G==0 then print("rm: missing operand")return end;local am=F.r or F.R;for a0,ag in ipairs(G)do local y=m(ag)local v=syscall.type(y)if not v then if not F.f then print("rm: cannot remove '"..ag.."': No such file or directory")end elseif v=="directory"then if not am then print("rm: cannot remove '"..ag.."': Is a directory")else Z(y)end else local h,X=pcall(syscall.remove,y)if not h then print("rm: cannot remove '"..ag.."': "..tostring(X))end end end end;a6.cp=function(...)local F,G=B({...},"rRp")if#G<2 then print("cp: missing operand")return end;local am=F.r or F.R;local W=m(G[#G])local an=syscall.type(W)=="directory"if#G>2 and not an then print("cp: target '"..G[#G].."' is not a directory")return end;for k=1,#G-1 do local V=m(G[k])local v=syscall.type(V)if not v then print("cp: '"..G[k].."': No such file or directory")elseif v=="directory"then if not am then print("cp: omitting directory '"..G[k].."'")else a2(V,an and W:gsub("/$","").."/"..q(G[k])or W)end else local s=an and W:gsub("/$","").."/"..q(G[k])or W;local h,X=U(V,s)if not h then print("cp: '"..G[k].."': "..tostring(X))end end end end;a6.mv=function(...)local F,G=B({...},"f")if#G<2 then print("mv: missing operand")return end;local W=m(G[#G])local an=syscall.type(W)=="directory"if#G>2 and not an then print("mv: target '"..G[#G].."' is not a directory")return end;for k=1,#G-1 do local V=m(G[k])local v=syscall.type(V)if not v then print("mv: '"..G[k].."': No such file or directory")else local s=an and W:gsub("/$","").."/"..q(G[k])or W;if v=="directory"then a2(V,s)Z(V)else local h,X=U(V,s)if h then pcall(syscall.remove,V)else print("mv: '"..G[k].."': "..tostring(X))end end end end end;a6.cat=function(...)local G={...}if#G==0 then while true do local h,w=pcall(syscall.read,0,4096)if not h or not w or w==""then break end;printInline(w)end;print("")return end;for a0,ag in ipairs(G)do local y=m(ag)if not syscall.exists(y)then print("cat: "..ag..": No such file or directory")else local h,u=pcall(syscall.open,y,"r")if not h then print("cat: "..ag..": "..tostring(u))else while true do local a4,w=pcall(syscall.read,u,65536)if not a4 or not w or w==""then break end;printInline(w)end;pcall(syscall.close,u)end end end end;a6.head=function(...)local ao={...}local ac=10;local ap={}local k=1;while k<=#ao do local H=ao[k]if H=="-n"then k=k+1;ac=tonumber(ao[k])or 10 elseif H:match("^%-n%d+$")then ac=tonumber(H:sub(3))elseif H:match("^%-%d+$")then ac=tonumber(H:sub(2))elseif H:sub(1,1)~="-"or H=="-"then ap[#ap+1]=H end;k=k+1 end;local aq=#ap>1;local function ar(N,as)if aq then syscall.devctl(1,"sfgc",0x0000FF)print("==> "..as.." <==")syscall.devctl(1,"sfgc",0xFFFFFF)end;local at=0;for au in(N.."\n"):gmatch("([^\n]*)\n")do if at>=ac then break end;print(au)at=at+1 end end;if#ap==0 then ar(t(0),"stdin")else for a0,ag in ipairs(ap)do if ag=="-"then ar(t(0),"stdin")else local z,X=x(m(ag))if not z then print("head: "..ag..": "..tostring(X))else ar(z,ag)end end end end end;a6.tail=function(...)local ao={...}local ac=10;local ap={}local k=1;while k<=#ao do local H=ao[k]if H=="-n"then k=k+1;ac=tonumber(ao[k])or 10 elseif H:match("^%-n%d+$")then ac=tonumber(H:sub(3))elseif H:match("^%-%d+$")then ac=tonumber(H:sub(2))elseif H:sub(1,1)~="-"or H=="-"then ap[#ap+1]=H end;k=k+1 end;local aq=#ap>1;local function av(N,as)if aq then syscall.devctl(1,"sfgc",0x0000FF)print("==> "..as.." <==")syscall.devctl(1,"sfgc",0xFFFFFF)end;local S=R(N)local ad=math.max(1,#S-ac+1)for I=ad,#S do print(S[I])end end;if#ap==0 then av(t(0),"stdin")else for a0,ag in ipairs(ap)do if ag=="-"then av(t(0),"stdin")else local z,X=x(m(ag))if not z then print("tail: "..ag..": "..tostring(X))else av(z,ag)end end end end end;a6.wc=function(...)local F,G=B({...},"lwc")local aw=not F.l and not F.w and not F.c;if aw then F.l=true;F.w=true;F.c=true end;local function at(N)local T,ax,ay=0,0,#N;for a0 in N:gmatch("\n")do T=T+1 end;for a0 in N:gmatch("%S+")do ax=ax+1 end;return T,ax,ay end;local function az(T,ax,L,aA)local n={}if F.l then n[#n+1]=string.format("%7d",T)end;if F.w then n[#n+1]=string.format("%7d",ax)end;if F.c then n[#n+1]=string.format("%7d",L)end;if aA then n[#n+1]=" "..aA end;print(table.concat(n))end;local aB,aC,aD=0,0,0;if#G==0 then local T,ax,L=at(t(0))az(T,ax,L)else for a0,ag in ipairs(G)do local z,X=x(m(ag))if not z then print("wc: "..ag..": "..tostring(X))else local T,ax,L=at(z)az(T,ax,L,ag)aB=aB+T;aC=aC+ax;aD=aD+L end end;if#G>1 then az(aB,aC,aD,"total")end end end;a6.grep=function(...)local F,G=B({...},"ivnlcrR",{["ignore-case"]=true,["invert-match"]=true})if#G==0 then print("grep: missing pattern")return end;local aE=G[1]if F.i or F["ignore-case"]then aE=aE:lower()end;local am=F.r or F.R;local aF=false;local function aG(N,as,aH)local at=0;local aI=0;local aJ=false;M(N,function(au)aI=aI+1;local aK=(F.i or F["ignore-case"])and au:lower()or au;local aL=aK:find(aE)~=nil;if F.v or F["invert-match"]then aL=not aL end;if aL then at=at+1;aJ=true;aF=true;if not F.l and not F.c then local ae=""if aH then ae=ae..as..":"end;if F.n then ae=ae..aI..":"end;print(ae..au)end end end)if F.l and aJ then print(as)end;if F.c then print((aH and as..":"or"")..at)end end;local function aM(y,as,aH)local z,X=x(y)if not z then print("grep: "..as..": "..tostring(X))return end;aG(z,as,aH)end;local function aN(aO,aP)local h,_=pcall(syscall.listdir,aO)if not h then return end;for a0,a1 in ipairs(_)do local aQ=aO:gsub("/$","").."/"..a1;local aA=(aP~=""and aP.."/"or"")..a1;local v=syscall.type(aQ)if v=="directory"then aN(aQ,aA)elseif v=="file"then aM(aQ,aA,true)end end end;if#G==1 then aG(t(0),"(stdin)",false)else local aH=#G>2 or am;for k=2,#G do local y=m(G[k])local v=syscall.type(y)if v=="directory"then if am then aN(y,G[k])else print("grep: "..G[k]..": Is a directory")end elseif v then aM(y,G[k],aH)else print("grep: "..G[k]..": No such file or directory")end end end end;a6.sort=function(...)local F,G=B({...},"rnu")local S={}local function aR(N)local aS=R(N)for a0,T in ipairs(aS)do S[#S+1]=T end end;if#G==0 then aR(t(0))else for a0,ag in ipairs(G)do local z,X=x(m(ag))if not z then print("sort: "..ag..": "..tostring(X))else aR(z)end end end;table.sort(S,function(ag,ay)if F.n then local aT=tonumber(ag:match("^%-?%d+%.?%d*"))or 0;local aU=tonumber(ay:match("^%-?%d+%.?%d*"))or 0;return F.r and aT>aU or aT<aU end;return F.r and ag>ay or ag<ay end)local aV=nil;for a0,T in ipairs(S)do if not F.u or T~=aV then print(T)aV=T end end end;a6.uniq=function(...)local F,G=B({...},"cdui")local N;if G[1]then local z,X=x(m(G[1]))if not z then print("uniq: "..G[1]..": "..tostring(X))return end;N=z else N=t(0)end;local aV,aW=nil,0;local ae={}local function aX(au,at)if F.d and at==1 then return end;if F.u and at>1 then return end;ae[#ae+1]=F.c and string.format("%7d %s",at,au)or au end;M(N,function(au)local aY=F.i and au:lower()or au;local aZ=F.i and(aV and aV:lower())or aV;if aY==aZ then aW=aW+1 else if aV~=nil then aX(aV,aW)end;aV=au;aW=1 end end)if aV~=nil then aX(aV,aW)end;if G[2]then local h,X=A(m(G[2]),table.concat(ae,"\n").."\n")if not h then print("uniq: "..G[2]..": "..tostring(X))end else for a0,T in ipairs(ae)do print(T)end end end;a6.tee=function(...)local F,G=B({...},"a")local a_=F.a and"a"or"w"local b0={}for a0,ag in ipairs(G)do local h,u=pcall(syscall.open,m(ag),a_)if not h then print("tee: "..ag..": "..tostring(u))else b0[#b0+1]=u end end;while true do local h,w=pcall(syscall.read,0,4096)if not h or not w or w==""then break end;pcall(syscall.write,1,w)for a0,u in ipairs(b0)do pcall(syscall.write,u,w)end end;for a0,u in ipairs(b0)do pcall(syscall.close,u)end end;a6.find=function(...)local ao={...}local b1,b2={},{}local b3,b4=nil,0;local k=1;while k<=#ao and ao[k]:sub(1,1)~="-"do b1[#b1+1]=ao[k]k=k+1 end;if#b1==0 then b1={"."}end;while k<=#ao do local b5=ao[k]if b5=="-name"then k=k+1;local aE="^"..(ao[k]or""):gsub("([%.%+%-%^%$%(%)%[%]%%])","%%%1"):gsub("%*",".*"):gsub("%?",".").."$"b2[#b2+1]=function(a0,a1,b6,b7)return a1:match(aE)~=nil end elseif b5=="-type"then k=k+1;local b8=ao[k]or""b2[#b2+1]=function(a0,a0,v,b6)if b8=="f"then return v=="file"elseif b8=="d"then return v=="directory"elseif b8=="l"then return v=="symlink"end;return true end elseif b5=="-maxdepth"then k=k+1;b3=tonumber(ao[k])or 0 elseif b5=="-mindepth"then k=k+1;b4=tonumber(ao[k])or 0 elseif b5=="-empty"then b2[#b2+1]=function(y,a0,v,b6)if v=="file"then local h,a3=pcall(syscall.stat,y)return h and a3 and(a3.size or 0)==0 elseif v=="directory"then local h,T=pcall(syscall.listdir,y)return h and T and#T==0 end;return false end end;k=k+1 end;local function b9(y,a1,v,ba)for a0,bb in ipairs(b2)do if not bb(y,a1,v,ba)then return false end end;return true end;local function bc(y,bd,ba)local v=syscall.type(y)if not v then return end;local a1=y:match("([^/]+)/?$")or y;if ba>=b4 and b9(y,a1,v,ba)then print(bd)end;if v=="directory"and(b3==nil or ba<b3)then local h,_=pcall(syscall.listdir,y)if h then table.sort(_)for a0,be in ipairs(_)do bc(y:gsub("/$","").."/"..be,bd:gsub("/$","").."/"..be,ba+1)end end end end;local a7=syscall.getcwd()for a0,bf in ipairs(b1)do local bg=bf=="."and a7 or m(bf)bc(bg,bf,0)end end;a6.stat=function(...)local a0,G=B({...},"")if#G==0 then print("stat: missing operand")return end;local function bh(n)local function ay(ac)return math.floor(n/2^ac)%2==1 end;return(ay(5)and"r"or"-")..(ay(4)and"w"or"-")..(ay(9)and"x"or"-")..(ay(3)and"r"or"-")..(ay(2)and"w"or"-")..(ay(8)and"x"or"-")..(ay(1)and"r"or"-")..(ay(0)and"w"or"-")..(ay(7)and"x"or"-")end;local function bi(n)local function ay(ac)return math.floor(n/2^ac)%2 end;local bj=ay(6)*4096+ay(5)*256+ay(4)*128+ay(9)*64+ay(3)*32+ay(2)*16+ay(8)*8+ay(1)*4+ay(0)*2+ay(7)*1;return string.format("%04o",bj)end;for a0,ag in ipairs(G)do local y=m(ag)if not syscall.exists(y)then print("stat: '"..ag.."': No such file or directory")else local v=syscall.type(y)local h,a3=pcall(syscall.stat,y)a3=h and a3 or{}local aD=v=="directory"and"d"or(v=="symlink"and"l"or"-")print(" File: "..ag)print(" Size: "..tostring(a3.size or 0).." Type: "..(v or"?"))print(" Owner: "..tostring(a3.owner or 0).." Group: "..tostring(a3.group or 0))print("Access: ("..bi(a3.perms or 0).."/"..aD..bh(a3.perms or 0)..")")if v=="symlink"then local a4,a5=pcall(syscall.readlink,y)if a4 then print(" Link: "..a5)end end;print("")end end end;a6.basename=function(...)local G={...}if#G==0 then print("basename: missing operand")return end;local n=G[1]while#n>1 and n:sub(-1)=="/"do n=n:sub(1,-2)end;local ay=n:match("([^/]+)$")or n;if G[2]and ay:sub(-#G[2])==G[2]then ay=ay:sub(1,#ay-#G[2])end;print(ay)end;a6.dirname=function(...)local G={...}if#G==0 then print("dirname: missing operand")return end;for a0,n in ipairs(G)do while#n>1 and n:sub(-1)=="/"do n=n:sub(1,-2)end;local s=n:match("^(.*)/[^/]+$")if not s then print(".")elseif s==""then print("/")else print(s)end end end;a6.df=function(...)local F,a0=B({...},"h")local function bk(ac)local ah={"K","M","G","T"}local k=0;while ac>=1024 and k<#ah do ac=ac/1024;k=k+1 end;if k==0 then return tostring(math.floor(ac))end;if ac<10 then return string.format("%.1f%s",ac,ah[k])end;return math.floor(ac)..ah[k]end;local function az(ac)return F.h and bk(ac)or tostring(ac)end;print(string.format("%-20s %10s %10s %10s %6s %-s","Filesystem","Size","Used","Avail","Use%","Mounted on"))local bl={{"$","/"},{"devfs0000","/dev/"},{"tmpfs0000","/tmp/"}}for a0,aL in ipairs(bl)do local bm,bn=aL[1],aL[2]print(string.format("%-20s %10s %10s %10s %6s %-s",bm,"?","?","?","?%",bn))end end;local function bo(aO,aP)local h,bp=pcall(syscall.listdir,aO)if not h or not bp then return{}end;local aj={}for a0,a1 in ipairs(bp)do if aP==""or a1:sub(1,#aP)==aP then local bq=(aO=="/"and"/"or aO.."/")..a1;local v=syscall.type(bq)aj[#aj+1]=v=="directory"and a1 .."/"or a1 end end;table.sort(aj)return aj end;local function br(aP)local aj={}local bs={}for bt in pairs(a6)do if aP==""or bt:sub(1,#aP)==aP then if not bs[bt]then aj[#aj+1]=bt;bs[bt]=true end end end;local bu=string.split(syscall.getEnviron("PATH")or"/bin/",":")for a0,n in ipairs(bu)do local h,bp=pcall(syscall.listdir,n)if h and bp then for a0,a1 in ipairs(bp)do local bq=(n:sub(-1)=="/"and n or n.."/")..a1;local bv=pcall(syscall.access,bq,"x")if bv and(aP==""or a1:sub(1,#aP)==aP)then if not bs[a1]then aj[#aj+1]=a1;bs[a1]=true end end end end end;table.sort(aj)return aj end;local function bw(_)if#_==0 then return""end;local bx=_[1]for k=2,#_ do local a3=_[k]local I=1;while I<=#bx and I<=#a3 and bx:sub(I,I)==a3:sub(I,I)do I=I+1 end;bx=bx:sub(1,I-1)if bx==""then return""end end;return bx end;local function by(bz)syscall.write(1,"\n")local bA=51;local bB=0;for a0,L in ipairs(bz)do if#L>bB then bB=#L end end;local bC=bB+2;local bD=math.max(1,math.floor(bA/bC))local k=0;for a0,L in ipairs(bz)do local bE=L..string.rep(" ",bC-#L)syscall.write(1,bE)k=k+1;if k%bD==0 then syscall.write(1,"\n")end end;if k%bD~=0 then syscall.write(1,"\n")end end;local function bF(bG,bH)local bI=bG:sub(1,bH-1)local bJ={}for b5 in bI:gmatch("%S+")do bJ[#bJ+1]=b5 end;local bK=bI:match("%S+$")or""local bL=#bJ==0 or bI:sub(-1)~=" "and#bJ==1;local bM,bN;if bK:find("/")then bM=bK:match("^(.*/)")or"/"bN=bK:match("[^/]*$")or""else bM=nil;bN=bK end;return bJ,bK,bL,bM,bN end;local bO={last=nil,idx=0,list={}}local function bP(bG,bH)local bJ,bK,bL,bM,bN=bF(bG,bH)local bQ;if bL then if bM then local aO=bM:sub(1,1)=="/"and bM or syscall.getcwd().."/"..bM;bQ=bo(aO,bN)for k,L in ipairs(bQ)do bQ[k]=bM..L end else bQ=br(bN)end else local aO,bR;if bM then aO=bM:sub(1,1)=="/"and bM or syscall.getcwd().."/"..bM;bR=bN else aO=syscall.getcwd()bR=bN end;bQ=bo(aO,bR)if bM then for k,L in ipairs(bQ)do bQ[k]=bM..L end end end;if#bQ==0 then return bG,bH,false end;local bS=bG.."\0"..tostring(bH)if bO.last~=bS then bO.last=bS;bO.idx=0;bO.list=bQ end;if#bQ==1 then local bT=bQ[1]local bU=bG:sub(1,bH-1-#bK)local bV=bG:sub(bH)local bW=bU..bT..bV;local bX=#bU+#bT+1;bO.last=nil;return bW,bX,true end;local bx=bw(bQ)if#bx>#bK then local bU=bG:sub(1,bH-1-#bK)local bV=bG:sub(bH)local bW=bU..bx..bV;local bX=#bU+#bx+1;bO.last=bW.."\0"..tostring(bX)bO.list=bQ;return bW,bX,true else by(bQ)return bG,bH,true end end;local function bY()syscall.devctl(1,"sfgc",0x00FF00)syscall.write(1,d)syscall.devctl(1,"sfgc",0xFFFFFF)syscall.write(1,":")syscall.devctl(1,"sfgc",0x24FFFF)syscall.write(1,syscall.getcwd())syscall.devctl(1,"sfgc",0xFFFFFF)syscall.write(1,"$ ")local bZ=syscall.devctl(1,"gpos")local b_=tonumber(bZ:sub(1,bZ:find(";")-1))local c0=tonumber(bZ:sub(bZ:find(";")+1))local bG=""local c1=false;local bH=1;local c2=0;local c3=true;local function c4()if#bG==0 then return""end;local a0,bK,bL,bM,bN=bF(bG,bH)if bH~=#bG+1 then return""end;local bQ;if bL then if bM then local aO=bM:sub(1,1)=="/"and bM or syscall.getcwd().."/"..bM;bQ=bo(aO,bN)for k,L in ipairs(bQ)do bQ[k]=bM..L end else bQ=br(bN)end else local aO,bR;if bM then aO=bM:sub(1,1)=="/"and bM or syscall.getcwd().."/"..bM;bR=bN else aO=syscall.getcwd()bR=bN end;bQ=bo(aO,bR)if bM then for k,L in ipairs(bQ)do bQ[k]=bM..L end end end;if#bQ==0 then return""end;local bx=bw(bQ)if#bx>#bK then return bx:sub(#bK+1)end;return""end;local function c5()syscall.devctl(1,"spos",b_,c0)syscall.write(1,string.sub(bG,1,bH-1))if c1 then syscall.devctl(1,"sfgc",0x000000)syscall.devctl(1,"sbgc",0xFFFFFF)end;if bH>#bG then syscall.write(1," ")else syscall.write(1,string.sub(bG,bH,bH))end;syscall.devctl(1,"sfgc",0xFFFFFF)syscall.devctl(1,"sbgc",0x000000)local bV=string.sub(bG,bH+1)syscall.write(1,bV)local c6=c4()if#c6>0 then syscall.devctl(1,"sfgc",0x6D00FF)syscall.write(1,c6)syscall.devctl(1,"sfgc",0xFFFFFF)syscall.write(1," ")else syscall.write(1," ")end end;while true do local c7=syscall.read(0)if c7 and c7~=""then if c7=="[D"then if bH>1 then bH=bH-1;c3=true end elseif c7=="[C"then if bH<=#bG then bH=bH+1;c3=true end elseif c7=="[A"then if c2<#e then c2=c2+1;bG=e[#e-c2+1]bH=#bG+1;c3=true end elseif c7=="[B"then if c2>1 then c2=c2-1;bG=e[#e-c2+1]bH=#bG+1;c3=true elseif c2==1 then c2=0;bG=""bH=1;c3=true end elseif c7=="[H"then bH=1;c3=true elseif c7=="[F"then bH=#bG+1;c3=true elseif c7=="[3~"then if bH<=#bG then bG=string.sub(bG,1,bH-1)..string.sub(bG,bH+1)c3=true end elseif c7=="\t"then local bW,bX,c8=bP(bG,bH)if c8 then bG=bW;bH=bX;local c9=syscall.devctl(1,"gpos")local ca=c9:find(";")local cb=tonumber(c9:sub(1,ca-1))local cc=tonumber(c9:sub(ca+1))if cb>1 then syscall.devctl(1,"spos",1,cc)local cd=syscall.devctl(1,"size")or"51;19"local aC=tonumber(cd:match("^(%d+)"))or 51;syscall.write(1,string.rep(" ",aC))syscall.devctl(1,"spos",1,cc)end;syscall.devctl(1,"sfgc",0x00FF00)syscall.write(1,d)syscall.devctl(1,"sfgc",0xFFFFFF)syscall.write(1,":")syscall.devctl(1,"sfgc",0x00FFFF)syscall.write(1,syscall.getcwd())syscall.devctl(1,"sfgc",0xFFFFFF)syscall.write(1,"$ ")c9=syscall.devctl(1,"gpos")ca=c9:find(";")b_=tonumber(c9:sub(1,ca-1))c0=tonumber(c9:sub(ca+1))c3=true end elseif c7=="\b"then if bH>1 then bG=string.sub(bG,1,bH-2)..string.sub(bG,bH)bH=bH-1;c3=true end elseif c7=="\n"then syscall.devctl(1,"sfgc",0xFFFFFF)syscall.devctl(1,"sbgc",0x000000)syscall.devctl(1,"spos",b_,c0)syscall.write(1,bG.." \n")return bG elseif#c7==1 and c7:byte(1)>=32 and c7:byte(1)<127 then bG=string.sub(bG,1,bH-1)..c7 ..string.sub(bG,bH)bH=bH+1;c3=true end end;local ce=math.floor(syscall.getUptime()/500)%2==0;if ce~=c1 then c1=ce;c3=true end;if c3 then c5()c3=false end end end;local function cf(cg,ch)syscall.devctl(1,"sfgc",0xFF0000)local a3=tostring(ch)local au,ci=a3:match("%]:(%d+): (.+)$")if not au then au,ci=a3:match(":(%d+): (.+)$")end;if au then printInline(cg..": error on line "..au..": ")print(ci)else print(cg..": "..a3)end;syscall.devctl(1,"sfgc",0xFFFFFF)end;local function cj(ck)do local cl=load("return "..ck,"@equation","t",{})if cl then local h,cm=pcall(cl)if h and type(cm)=="number"then print(cm)return end end end;f=false;local G=string.split(ck," ")for k=#G,1,-1 do if G[k]==""then table.remove(G,k)end end;if#G==0 then return end;if a6[G[1]]then local h,X=pcall(a6[G[1]],table.unpack(G,2))if not h then cf(G[1],X)end;return end;local cn=""if string.find(G[1],"/")then local co=G[1]if co:sub(1,1)~="/"then co=syscall.getcwd().."/"..co end;if c.exists(co)then cn=co end else local bu=string.split(syscall.getEnviron("PATH"),":")for a0,n in pairs(bu)do if c.exists(n..G[1])then cn=n..G[1]break end end;if cn==""then local a7=syscall.getcwd()local co=a7 ..(a7:sub(-1)=="/"and""or"/")..G[1]if c.exists(co)then cn=co end end end;if cn==""then print(G[1]..": Command not found")return end;local cg=cn:match("([^/]+)$")or G[1]local bv,cp=pcall(syscall.access,cn,"x")if not bv then syscall.devctl(1,"sfgc",0xFF0000)print(cg..": Permission denied")syscall.devctl(1,"sfgc",0xFFFFFF)return end;local cq=syscall.spawn(function()syscall.open("/dev/tty/1","r")syscall.open("/dev/tty/1","w")syscall.open("/dev/null","w")syscall.exec(cn,{table.unpack(G,2)})end,cg)while true do local cr,ab=syscall.collect(cq)if cr then if ab then print("\nTask exited with code:\n"..tostring(ab))end;return end;if f then local a4=syscall.kill(cq)if a4 then syscall.devctl(1,"sbgc",16)syscall.devctl(1,"sfgc",0xFF0000)print("\nProgram Terminated.")syscall.devctl(1,"sfgc",0xFFFFFF)end;f=false;break end;sleep(0.05)end end;while true do local ck=bY()if ck~=""then if ck~=e[#e]then table.insert(e,ck)end;cj(ck)end end end,debug.traceback)if not a then syscall.log("Error running shell: "..b,"ERROR")syscall.devctl(1,"sfgc",0xFF0000)syscall.devctl(1,"sbgc",0x000000)print()print("Error running shell: ")print(b)end
|