Shell API

From ComputerCraft
Jump to navigation Jump to search
FunctionFunctionshell.aliases
Returns a list of all aliases.
Syntax shell.aliases()
Returns table
Part of CC:Tweaked (source)
API shell
ExampleExamplePrint all aliases
Print all aliases.
Code
for alias,program in pairs(shell.aliases()) do
  print(alias..": "..program)
end
Output rm: delete

dir: list
clr: clear
sh: shell
ls: list
cp: copy
foreground: fg
background: bg
mv: move

rs: redstone


FunctionFunctionshell.clearAlias
Clears an alias.
Syntax shell.clearAlias()
Returns nil
Part of CC:Tweaked (source)
API shell
ExampleExampleClears an Alias
Clears the alias "rm".
Code
shell.clearAlias("rm")

Shell.complete Shell.completeProgram

FunctionFunctionshell.dir
Returns the current shell directory. Setable by shell.setDir.
Syntax shell.dir()
Returns string path
Part of CC:Tweaked
API shell
ExampleExampleGet the current shell directory.
Returns the current shell directory.
Code
shell.dir()
Output
Path of the current shell directory.


FunctionFunctionshell.exit
Close the current shell.
Syntax shell.exit()
Returns nil
Part of CC:Tweaked (source)
API shell
ExampleExampleClose the current shell.
Close the current shell.
Code
shell.exit()

Shell.getCompletionInfo

FunctionFunctionshell.getRunningProgram
Returns the running program executed by shell.run.
Syntax shell.getRunningProgram()
Returns string path
Part of CC:Tweaked
API shell
ExampleExampleGet the path of a running program.
Returns the running program.
Code
shell.getRunningProgram()
Output
Running program.


FunctionFunctionshell.openTab
Run a program in a new multishell tab in the shell enviroment. This function only exits if multishell is enabled.
Syntax shell.openTab()
Returns number tabid
Part of CC:Tweaked (source)
API shell
ExampleExampleRun a Program in a new tab.
Run "lua" in a new tab.
Code
shell.openTab("lua")


FunctionFunctionshell.path
Returns the Shellpath. The Shellpath is a list of folders, where the shell are searching for programs. The directories are separated with :.
Syntax shell.path()
Returns string
Part of CC:Tweaked (source)
API shell
ExampleExampleGet the Shellpath
Print the Shellpath.
Code
print(shell.path())
Output .:/rom/programs:/rom/programs/advanced:/rom/programs/rednet:/rom/programs/fun:/rom/programs/fun/advanced:/rom/programs/http


FunctionFunctionshell.programs
Returns a list of all Programs in the Shellpath.
Syntax shell.programs()
Returns table
Part of CC:Tweaked (source)
API shell
ExampleExampleGet a List of all Progarms in the Shellpath
Get a List of all Progarms in the Shellpath and print it.
Code
for k,v in ipairs(shell.programs()) do
  write(v.." ")
end
Output adventure alias apis bg cd chat clear copy delete dj drive edit eject emu exit fg gps h hello help id label list lua mkdir monitor move multishell paint pastebin peripherals programs reboot redirection redstone rename repeat set shell shutdown time type wget worm

Shell.resolve Shell.resolveProgram

,
FunctionFunctionshell.run
Runs a command in the computer's or turtle's shell.
Syntax shell.run()
Returns boolean success
Part of CC:Tweaked
API shell
ExampleExampleExecute a command in the shell
Opens the lua interface
Code
shell.run("lua")
Output
(Lua program is now running.)
ExampleExampleExecute a splitted command in the shell
Lists all files/directories in /rom
Code
shell.run("list", "/rom")
Output
All files/directories in /rom


FunctionFunctionshell.setAlias
Set an alias.
Syntax shell.setAlias()
Returns nil
Part of CC:Tweaked (source)
API shell
ExampleExampleSet an Alias
Set "rd" as alias for "redirection".
Code
shell.setAlias("rd", "redirection")

Shell.setCompletionFunction

FunctionFunctionshell.setDir
Sets the current shell directory. Throws a error, if the directory are not exists. You can get the current shell directory with shell.dir.
Syntax shell.setDir()
Returns nil
Part of CC:Tweaked (source)
API shell
ExampleExampleSet the current shell directory.
Set the current shell directory to "/rom".
Code
shell.setDir("/rom")


FunctionFunctionshell.setPath
Set the Shellpath. The Shellpath is a list of folders, where the shell are searching for programs. The directories are separated with :.
Syntax shell.setPath()
Returns nil
Part of CC:Tweaked (source)
API shell
ExampleExampleSet the Shellpath
Add "/programs" to the Shellpath.
Code
shell.setPath(shell.path()..":/programs")


FunctionFunctionshell.switchTab
Switch to another multishell tab. This function only exists if multishell is enabled.
Syntax shell.switchTab()
Returns nil
Part of CC:Tweaked (source)
API shell
ExampleExampleSwitch the tab.
Switch to tab 1.
Code
shell.switchTab(1)