Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function FakeShell()
- local shell = {}
- shell.__cdir = ""
- shell.__path = ".:/rom/programs:/rom/programs/advanced:/rom/programs/rednet:/rom/programs/fun:/rom/programs/http:/rom/programs/fun/advanced"
- shell.__stack = {}
- shell.dir = function()
- return shell.__cdir
- end
- shell.setDir = function(path)
- shell.__cdir = path
- end
- shell.resolve = function(localPath)
- return fs.combine(shell.__cdir, localPath)
- end
- shell.resolveProgram = function(name)
- local firstChar = name:sub(1, 1)
- if firstChar == "/" or firstChar == "\\" then
- local path = fs.combine("", name)
- if fs.exists(path) and not fs.isDir(path) then return path end
- return nil
- end
- for path in shell.__path:gmatch("[^:]+") do
- path = fs.combine(shell.resolve(path), name)
- if fs.exists(path) and not fs.isDir(path) then return path end
- end
- return nil
- end
- shell.getRunningProgram = function()
- return shell.__stack[#shell.__stack]
- end
- shell.run = function(program, ...)
- local path = shell.resolveProgram(program)
- table.insert(shell.__stack, path)
- os.run({ shell = shell }, path, ...)
- end
- shell.path = function()
- return shell.__path
- end
- shell.setPath = function(path)
- shell.__path = path
- end
- return shell
- end
Advertisement
Add Comment
Please, Sign In to add comment