Class Shell
The Shell class is the primary place user can call to get access to shell functionality.
Inheritance
Inherited Members
Namespace: Dotnet.Shell.API
Assembly: dotnet-shell-lib.dll
Syntax
public class Shell
Constructors
| Improve this Doc View SourceShell(Boolean)
Initializes a new instance of the Shell class.
Declaration
public Shell(bool loadHistory = true)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | loadHistory |
Fields
| Improve this Doc View SourceDefaultScriptExtension
The default extension for scripts run through the scripting engine
Declaration
public const string DefaultScriptExtension = ".nsh"
Field Value
| Type | Description |
|---|---|
| System.String |
ForegroundProcess
The foreground process
Declaration
public ProcessEx ForegroundProcess
Field Value
| Type | Description |
|---|---|
| ProcessEx |
HistoryLoadedTask
The history loaded task, wait on this to ensure all history elements have been loaded into memory
Declaration
public Task HistoryLoadedTask
Field Value
| Type | Description |
|---|---|
| System.Threading.Tasks.Task |
LastExecutedProcess
The last executed process
Declaration
public ProcessEx LastExecutedProcess
Field Value
| Type | Description |
|---|---|
| ProcessEx |
Properties
| Improve this Doc View SourceAssemblyLocation
Gets the executing program location.
Declaration
public static string AssemblyLocation { get; }
Property Value
| Type | Description |
|---|---|
| System.String | The assembly location. |
AutoCompletionHandlers
A list of autocompletion handlers which can be used by the user to extend autocompletion results
Declaration
public virtual List<Func<string, int, Task<IEnumerable<Suggestion>>>> AutoCompletionHandlers { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.List<System.Func<System.String, System.Int32, System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<Suggestion>>>> | The autocompletion handlers. |
BackgroundProcesses
Gets the current set of background processes.
Declaration
public ProcessEx[] BackgroundProcesses { get; }
Property Value
| Type | Description |
|---|---|
| ProcessEx[] | The background processes. |
BasePath
Gets the base path. On Linux this is / on Windows C:\
Declaration
public static string BasePath { get; }
Property Value
| Type | Description |
|---|---|
| System.String | The base path. |
CommandHandlers
Gets or sets the command handler. This is called after the user has hit Enter and can be used to replace what was entered
Declaration
public virtual List<Func<string, string>> CommandHandlers { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.List<System.Func<System.String, System.String>> | The command handler. |
Error
This function can be called to render a pretty error message.
Declaration
public Action<string> Error { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Action<System.String> |
History
The shell history
Declaration
public virtual List<HistoryItem> History { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.List<HistoryItem> |
HomeDirectory
Gets the home directory.
Declaration
public virtual string HomeDirectory { get; }
Property Value
| Type | Description |
|---|---|
| System.String | The home directory. |
LastExitCode
Gets or sets the last exit code.
Declaration
public int LastExitCode { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 | The last exit code. |
LoadAssemblyFromFileAsync
This function can be called to load a .NET DLL into memory
Declaration
public Func<string, Task> LoadAssemblyFromFileAsync { get; }
Property Value
| Type | Description |
|---|---|
| System.Func<System.String, System.Threading.Tasks.Task> |
LoadScriptFromFileAsync
This function can be called to load script into memory
Declaration
public Func<string, Task> LoadScriptFromFileAsync { get; }
Property Value
| Type | Description |
|---|---|
| System.Func<System.String, System.Threading.Tasks.Task> |
Paths
Gets the paths.
Declaration
public List<string> Paths { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.List<System.String> | The paths. |
Prompt
Gets or sets the function used to return the prompt string. This function is generally set by the user to customize the prompt
Declaration
public Func<ColorString> Prompt { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Func<ColorString> | The prompt function |
WorkingDirectory
Gets or sets the working directory.
Declaration
public string WorkingDirectory { get; }
Property Value
| Type | Description |
|---|---|
| System.String | The working directory. |
Methods
| Improve this Doc View SourceAddCmdAlias(String, String)
Adds a command alias An example of this is Shell.AddCmdAlias("ls", "ls --color=auto ");
Declaration
public void AddCmdAlias(string command, string replacement)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | command | The user entered command. |
| System.String | replacement | The C# replacement. |
AddCSAlias(String, String)
Adds a shell alias for C# commands An example of this is Shell.AddCSAlias("echo", "Console.WriteLine("{0}");");
Declaration
public void AddCSAlias(string command, string replacement)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | command | The user entered command. |
| System.String | replacement | The C# replacement. |
ChangeDir(String)
API call to changes the working directory.
Declaration
public void ChangeDir(string location)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | location | The location. |
Exceptions
| Type | Condition |
|---|---|
| System.IO.DirectoryNotFoundException |
ConvertPathToAbsolute(String)
Converts the a file path to absolute based on the current working directory This is a public API and is used in #load
Declaration
public string ConvertPathToAbsolute(string file)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | file | The file path |
Returns
| Type | Description |
|---|---|
| System.String |
Exceptions
| Type | Condition |
|---|---|
| System.IO.FileNotFoundException | The file requested: " + file + " does not exist and cannot be loaded |
Execute(String, Object)
Executes the an OS command synchronously.
Declaration
public ProcessEx Execute(string input, object r = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | input | The command line. |
| System.Object | r | The redirection conditions, if any |
Returns
| Type | Description |
|---|---|
| ProcessEx | Task |
ExecuteAsync(String, Object)
Executes the an OS command asynchronously.
Declaration
public Task<ProcessEx> ExecuteAsync(string input, object r = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | input | The command line. |
| System.Object | r | The redirection conditions, if any |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task<ProcessEx> | Task |
RemoveCmdAlias(String)
Removes a command alias.
Declaration
public void RemoveCmdAlias(string command)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | command | The command. |
RemoveCSAlias(String)
Removes a C# alias.
Declaration
public void RemoveCSAlias(string command)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | command | The command. |
TryReplaceWithCSAlias(String)
Tries to replace the string with an alias which is a piece of C#
Declaration
public string TryReplaceWithCSAlias(string input)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | input | The user input command |
Returns
| Type | Description |
|---|---|
| System.String | Command with possible alias replacement |