OneOS.ToolBarColour=colours.black;OneOS.ToolBarTextColour=colours.white;local a={}local b={}local function c(d,...)local e=OneOS.Shell.resolveProgram(d)if e~=nil then b[#b+1]=e;local f=shell;f.programs=OneOS.Shell.programs;local g=OneOS.OSRun({fs=OneOS.FS,shell=f,io=OneOS.IO,loadfile=OneOS.LoadFile,os=os,sleep=os.sleep},e,...)b[#b]=nil;return g else printError("No such program")return false end end;local function h(i)local j={}for k in string.gmatch(i,"[^ \t]+")do table.insert(j,k)end;local l=j[1]if l then return c(l,unpack(j,2))end;return false end;local m={['rom/programs/cd']={'path'},['rom/programs/copy']={'source','destination'},['rom/programs/delete']={'path'},['rom/programs/edit']={'path'},['rom/programs/eject']={'side'},['rom/programs/gps']={'locate'},['rom/programs/help']={'topic'},['rom/programs/label']={'set','text'},['rom/programs/mkdir']={'path'},['rom/programs/monitor']={'side','program','arguments'},['rom/programs/move']={'source','destination'},['rom/programs/color/paint']={'path'},['rom/programs/http/pastebin']={'get','code','filename'},['rom/programs/redpulse']={'side','count','period'},['rom/programs/redset']={'side','true/false'},['rom/programs/redstone']={'side','true/false'},['rom/programs/rename']={'source','destination'},['rom/programs/type']={'path'},['rom/programs/bg']={'program'},['rom/programs/fg']={'program'},['rom/programs/rednet/chat']={'join','hostname','username'},['rom/programs/turtle/craft']={'amount'},['rom/programs/turtle/equip']={'slot','side'},['rom/programs/turtle/excavate']={'diameter'},['rom/programs/turtle/go']={'direction','distance'},['rom/programs/turtle/refuel']={'amount'},['rom/programs/turtle/tunnel']={'length'},['rom/programs/turtle/turn']={'direction','turns'},['rom/programs/turtle/unequip']={'side'}}local n,o,p,q;if term.isColour()then n=colours.yellow;o=colours.white;q=colours.grey;p=colours.black else n=colours.white;o=colours.white;q=colours.black;p=colours.black end;term.setCursorPos(1,2)term.setBackgroundColor(p)term.setTextColour(n)term.write(os.version())term.setTextColour(o)term.write(' Quick Shell')print()term.setTextColour(o)local function r(s)local t=0;local u=0;repeat u=string.find(s,"/",t)if u~=nil then t=u+1 end until u==nil;return string.gsub(s,string.sub(s,t),"")end;local function k(s,v)if#s==0 then return''end;local w={}local function x(y)if y and type(y)=='table'then for z,A in ipairs(y)do local B=true;for C,D in ipairs(w)do if D==A then B=false;break end end;if B then table.insert(w,A)end end elseif y then table.insert(w,y)end end;if v=='program'then x(OneOS.Shell.resolveProgram(s))x(OneOS.Shell.aliases())x(OneOS.Shell.programs())elseif v=='side'then x({'left','right','top','bottom','front','back'})x(peripheral.getNames())elseif v=='direction'then x({'left','right','forward','back','down','up'})elseif v=='true/false'then x({'true','false'})elseif v=='set'then x({'get','set','clear'})elseif v=='locate'then x({'locate','host'})elseif v=='set'then x({'get','set','clear'})elseif v=='get'then x({'get','put','run'})elseif v=='topic'then x(help.topics())x('index')elseif v=='path'or v=='source'then local E=r(s)local F,G=r(E)if not OneOS.FS.isDir(F)then return''end;local w=OneOS.FS.list(F)for z,H in ipairs(w)do if string.lower(OneOS.FS.getName(string.sub(OneOS.FS.getName(H),1,string.len(OneOS.FS.getName(s)))))==string.lower(OneOS.FS.getName(s))then return F..H end end;return''end;for z,H in ipairs(w)do if string.lower(string.sub(H,1,string.len(s)))==string.lower(s)then return H end end;return''end;local function I(J,K)term.setCursorBlink(true)local L=""local M=nil;local N=0;if J then J=string.sub(J,1,1)end;local O,P=term.getSize()local Q,R=term.getCursorPos()local S=''local T=false;local function U(V,W)local X=0;if Q+N>=O then X=Q+N-O end;term.setCursorPos(1,R)term.clearLine()term.setBackgroundColor(p)term.setTextColour(n)term.write(shell.dir().."> ")if not T and not W then term.setCursorPos(Q,R)term.setTextColour(q)S=k(L,'program')term.write(S)elseif not W and T and N>=#S+1 then local Y=m[OneOS.Shell.resolveProgram(S)]previousArgs=''if Y then term.setCursorPos(Q+#L,R)if L:sub(-1)~=' 'then term.write(' ')term.setCursorPos(Q+#L+1,R)end;term.setTextColour(q)local j={}for Z in string.gmatch(L,"[^ \t]+")do table.insert(j,Z)end;table.remove(j,1)for z,v in ipairs(Y)do if#j<z then term.write(v..' ')elseif z==#j and L:sub(-1)~=' 'then term.setCursorPos(Q+#L-#j[z],R)local _=k(j[z],v)if#_~=0 then term.write(_..' ')else term.write(j[z]..' ')end end end end end;term.setTextColour(o)term.setCursorPos(Q,R)local a0=V or J;if a0 then term.write(string.rep(a0,string.len(L)-X))else term.write(string.sub(L,X+1))end;term.setCursorPos(Q+N-X,R)end;while true do local a1,a2=os.pullEvent()if a1=="char"then L=string.sub(L,1,N)..a2 ..string.sub(L,N+1)if T and N<=#S or not T and a2==' 'then local t,len=L:find("[^ \t]+")if t and len then S=L:sub(t,len)T=true end end;term.setCursorPos(1,2)N=N+1;U()elseif a1=="key"then if a2==keys.enter then U(nil,true)break elseif a2==keys.tab then if N>=#S+1 and N==#L then local Y=m[OneOS.Shell.resolveProgram(S)]local a3=''local j={}for k in string.gmatch(L,"[^ \t]+")do table.insert(j,k)end;if#j==0 then return end;if Y then k(j[#j],Y[#j-1])end;if#a3~=0 then L=''j[#j]=a3;for z,A in ipairs(j)do L=L..A..' 'end;N=#L;U()else L=L..' 'N=#L;U()end else local a3=k(L,'program')if#a3~=0 then N=#a3+1;L=a3 ..' 'T=true;S=a3;U()end end elseif a2==keys.left then if N>0 then N=N-1;U()end elseif a2==keys.right then if N<string.len(L)then U(" ")N=N+1;U()end elseif a2==keys.up or a2==keys.down then if K then U(" ")if a2==keys.up then if M==nil then if#K>0 then M=#K end elseif M>1 then M=M-1 end else if M==#K then M=nil elseif M~=nil then M=M+1 end end;if M then L=K[M]N=string.len(L)else L=""N=0 end;U()end elseif a2==keys.backspace then if N==#L and string.sub(L,N,N)==' 'then local j={}for k in string.gmatch(L,"[^ \t]+")do table.insert(j,k)end;table.remove(j,#j)L=''for z,A in ipairs(j)do L=L..A..' 'end;N=#L;if#j==0 then S=''T=false end;U()elseif N>0 then U(" ")L=string.sub(L,1,N-1)..string.sub(L,N+1)if T and N<=#S then local t,len=L:find("[^ \t]+")if t and len then S=L:sub(t,len)end end;N=N-1;U()end elseif a2==keys.home then U(" ")N=0;U()elseif a2==keys.delete then if N<string.len(L)then U(" ")L=string.sub(L,1,N)..string.sub(L,N+2)U()end elseif a2==keys["end"]then U(" ")N=string.len(L)U()end end end;term.setCursorBlink(false)term.setCursorPos(O+1,R)print()return L end;local a4={}while not bExit do term.setBackgroundColor(p)term.setTextColour(n)term.write(shell.dir().."> ")term.setTextColour(o)local a5=I(nil,a4)if a5 then local Y={}for v in a5:gmatch('%S+')do table.insert(Y,v)end;if not Y[1]or Y[1]==''then elseif Y[1]=='shutdown'then term.setTextColour(n)print('See ya!')sleep(1)OneOS.Shutdown()elseif Y[1]=='reboot'then term.setTextColour(n)print('See ya!')sleep(1)OneOS.Reboot()elseif Y[1]=='exit'then OneOS.Close()else local E=OneOS.Shell.resolveProgram(shell.dir()..'/'..Y[1])if E==nil then E=OneOS.Shell.resolveProgram(Y[1])end;if E~=nil then Y[1]=E;if E:sub(1,3)=='rom'then h(table.concat(Y," "))else h(table.concat(Y," "))end else printError("The file '"..Y[1].."' does not exist")end end;table.insert(a4,a5)end end