Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Creddits to Aio 2022
- --Created on july the 4:th 2022 this is a somewhat safer terminal program called
- --AST (AioSecureTerminal)
- --NOTE: It IS escapable and is only intended to reduce the risk of operator error
- print("Starting")
- function reset()
- term.setCursorPos(1,1)
- term.clear()
- history={}
- shell.run("mkdir ./trash")
- shell.run("mkdir ./home")
- LLCPath = {}
- CPath = "."
- CPI = CPath
- for s=1,20 do
- shell.run("cd ..")
- end
- LastCommand = ""
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.white)
- end
- function command(s)
- if s == "" or s == "last" then
- command(LastCommand)
- else
- LastCommand = s
- end
- print("")
- if s == "ls" then
- shell.run("dir")
- return "safe exit"
- end
- if s == "reset" or s == "clear" then
- reset()
- end
- if s == "help" then
- term.setTextColor(colors.white)
- print("exit - esacpe the terminal")
- print("cd - change directory")
- print("'cd' or 'cd ~' will change to ./home")
- print("Due to bad coding, recursive CD:s breaks the pwd and CPI functions")
- print("pwd - attempts to show the current directory")
- print("rm - will move files/folders to ./trash")
- print("reset / clear - clears the screen and moves to ./")
- print("'' / last - activates the last command")
- print("")
- print("1/2 press enter to continue")
- read()
- end
- if string.sub(s,1,2) == "cd" then
- CPI = CPath
- if s == "cd ~" or s == "cd" then
- shell.run("cd ./")
- shell.run("cd home")
- LLCPath = {"./~"}
- CPath = "./home"
- elseif s == "cd .." then
- CPI = CPath
- if CPath == "." then
- printError("Already on ./")
- else
- shell.run("cd ..")
- t = CPath
- CPath = LLCPath[#LLCPath]
- LLCPath[#LLCPath] = nil
- end
- elseif string.sub(s,1,3) == "cd " then
- CPI = "?"
- u = 1
- LLCPath = {}
- for i=1,string.len(s.."/"..CPath) do
- if string.sub(CPath.."/"..s,i,i) == "/" then
- LLCPath[#LLCPath+1] = string.sub(CPath.."/"..s,u,(i-1))
- u = i
- end
- end
- shell.run(s)
- --LLCPath[#LLCPath+1] = CPath
- CPath = CPath.."/"..string.sub(s,3,string.len(s))
- else
- shell.run(s)
- end
- elseif s == "pwd" then
- print(CPath)
- elseif string.sub(s,1,3) == "rm " then
- if fs.exists(string.sub(s,4,string.len(s))) then
- if fs.isDir(string.sub(s,4,string.len(s))) then
- term.setTextColor(colors.yellow)
- print("You are about to remove a directory!")
- print("Are you sure? [Y/n]")
- if string.upper(read()) == "Y" then
- shell.run("mv",string.sub(s,3,string.len(s)),"./trash")
- end
- else
- shell.run("mv", string.sub(s,3,string.len(s)),"./trash")
- end
- else
- printError("File or directory not found")
- end
- return "safe exit"
- elseif s == "ls" then
- shell.run("dir")
- elseif string.sub(s,1,3) == "bg " or string.sub(s,1,3) == "fg " or s == "fg" or s == "bg" then
- printError("Multitasking is not allowed for safety reasons")
- else
- shell.run(s)
- end
- end
- reset()
- print("Welcome!")
- History = {}
- bo = 0
- while true do
- if bo == 5 then
- term.setTextColor(colors.brown)
- command("pwd")
- print("")
- sleep(0)
- bo = 0
- else
- bo = bo + 1
- end
- OX,OY = term.getCursorPos()
- term.setCursorPos(1,OY-1)
- term.setTextColor(colors.white)
- term.clearLine()
- print(" > ")
- term.setCursorPos(string.len(" > "),OY-1)
- term.setTextColor(colors.gray)
- print(os.date())
- term.setTextColor(colors.blue)
- term.setCursorPos(string.len(" >",os.date())+1,OY-1)
- o = read()
- History[#History+1] = o
- if o == "save" then
- print("Location from ./?")
- o = read()
- if fs.exists(o) then
- printError("Location exists aborting")
- else
- h = fs.open(o,"w")
- for i=1,#History do
- h.writeLine(History[i])
- end
- h.close()
- end
- elseif o == "exit" then
- break
- end
- command(o)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement