Version 0.0.0-0

SKShell Reference

File
ShellKit/SKShell.h
Copyright
© (c) 2017, Jean-David Gadina - www.xs-labs.com
Date
Monday, May 15, 2017
Includes

Class SKShell

Attributes

Superclass
NSObject

- addPromptPart: Top

Adds a part to the current prompt parts

- ( void )addPromptPart:( NSString * )part;

Discussion

Only applicable if the prompt hierarchy is enabled.

See also

- commandIsAvailable: Top

Checks if a shell command is available

- ( BOOL )commandIsAvailable: ( NSString * )command;

Discussion

Commands are found using `which`, invoked through the logn shell.

Parameters
  • command
    The command name
Return value

YES is the command is available, otherwise NO

+ currentShell Top

Gets the instance representing the current shell

+ ( instancetype )currentShell;

Discussion

Although a `SKShell` can be instanciated, it is advised to alyways use this shared instance.

- pathForCommand: Top

Gets the paths of a shell command

- ( nullable NSString * )pathForCommand: ( NSString * )command;

Discussion

Commands are found using `which`, invoked through the logn shell.

Parameters
  • command
    The command name
Return value

The full path to the command, or nil

- printError: Top

Prints an error

- ( void )printError: ( nullable NSError * )error;

Discussion

If the `error` param is nil, this method will print a generic error message. Errors are printed in red if colors are available/enabled and with an error sign if status icons are enabled.

Parameters
  • error
    The error object to print

- printErrorMessage: Top

Prints an error message

- ( void )printErrorMessage: ( NSString * )format, ... NS_FORMAT_FUNCTION( 1, 2 );

Parameters
  • format
    The error message format
  • ...
    Optional parameters for the format string
See also

- printInfoMessage: Top

Prints an info message

- ( void )printInfoMessage: ( NSString * )format, ... NS_FORMAT_FUNCTION( 1, 2 );

Discussion

Info messages are printed in blue if colors are available/enabled and with an info sign if status icons are enabled.

Parameters
  • format
    The info message format
  • ...
    Optional parameters for the format string

- printMessage: Top

Prints a message

- ( void )printMessage: ( NSString * )format, ... NS_FORMAT_FUNCTION( 1, 2 );

Parameters
  • format
    The message format
  • ...
    Optional parameters for the format string

- printMessage:color: Top

Prints a message with a color

- ( void )printMessage: ( NSString * )format color: ( SKColor )color, ... NS_FORMAT_FUNCTION( 1, 3 );

Discussion

Colors will only be printed if the terminal supports them and if they are enabled.

Parameters
  • format
    The message format
  • color
    The message color
  • ...
    Optional parameters for the format string
See also

- printMessage:color: Top

Prints a message with a color

- ( void )printMessage: ( NSString * )format status: ( SKStatus )status color: ( SKColor )color, ... NS_FORMAT_FUNCTION( 1, 4 );

Discussion

Statuses will be printed as an emoji, if status icons are enabled. Colors will only be printed if the terminal supports them and if they are enabled.

Parameters
  • format
    The message format
  • status
    The message status
  • color
    The message color
  • ...
    Optional parameters for the format string
See also

- printMessage:status: Top

Prints a message with a status

- ( void )printMessage: ( NSString * )format status: ( SKStatus )status, ... NS_FORMAT_FUNCTION( 1, 3 );

Discussion

Statuses will be printed as an emoji, if status icons are enabled.

Parameters
  • format
    The message format
  • status
    The message status
  • ...
    Optional parameters for the format string
See also

- printMessage:status:color: Top

Prints a message with a color

- ( void )printMessage: ( NSString * )format status: ( SKStatus )status color: ( SKColor )color, ... NS_FORMAT_FUNCTION( 1, 4 );

Discussion

Statuses will be printed as an emoji, if status icons are enabled. Colors will only be printed if the terminal supports them and if they are enabled.

Parameters
  • format
    The message format
  • status
    The message status
  • color
    The message color
  • ...
    Optional parameters for the format string

- printSuccessMessage: Top

Prints a success message

- ( void )printSuccessMessage: ( NSString * )format, ... NS_FORMAT_FUNCTION( 1, 2 );

Discussion

Success messages are printed in green if colors are available/enabled and with a checkmark sign if status icons are enabled.

Parameters
  • format
    The success message format
  • ...
    Optional parameters for the format string

- printWarningMessage: Top

Prints an warning message

- ( void )printWarningMessage: ( NSString * )format, ... NS_FORMAT_FUNCTION( 1, 2 );

Discussion

Warnings are printed in yellow if colors are available/enabled and with an warning sign if status icons are enabled.

Parameters
  • format
    The warning message format
  • ...
    Optional parameters for the format string

- removeLastPromptPart Top

Removes the last part of the current prompt parts

- ( void )removeLastPromptPart;

Discussion

Only applicable if the prompt hierarchy is enabled.

See also

- runCommand: Top

Executes a shell command synchronously

- ( BOOL )runCommand: ( NSString * )command;

Discussion

Command can be a complex shell commands.

Parameters
  • command
    The command to execute
Return value

YES if the command executed successfully, otherwise NO

- runCommand: Top

Executes a shell command synchronously

- ( BOOL )runCommand: ( NSString * )command stdandardInput: ( nullable NSString * )input;

Discussion

Command can be a complex shell commands.

Parameters
  • command
    The command to execute
  • input
    An optional string to use as standard input for the command
Return value

YES if the command executed successfully, otherwise NO

- runCommand: Top

Executes a shell command synchronously

- ( BOOL )runCommand: ( NSString * )command completion: ( nullable SKShellCommandCompletion )completion;

Discussion

Command can be a complex shell commands.

Parameters
  • command
    The command to execute
  • completion
    An optional completion block
Return value

YES if the command executed successfully, otherwise NO

See also

- runCommand: Top

Executes a shell command synchronously

- ( BOOL )runCommand: ( NSString * )command stdandardInput: ( nullable NSString * )input completion: ( nullable SKShellCommandCompletion )completion;

Discussion

Command can be a complex shell commands.

Parameters
  • command
    The command to execute
  • input
    An optional string to use as standard input for the command
  • completion
    An optional completion block
Return value

YES if the command executed successfully, otherwise NO

See also

- runCommand: Top

Executes a shell command asynchronously

- ( void )runCommandAsynchronously: ( NSString * )command;

Discussion

Command can be a complex shell commands.

Parameters
  • command
    The command to execute

- runCommand: Top

Executes a shell command asynchronously

- ( void )runCommandAsynchronously: ( NSString * )command stdandardInput: ( nullable NSString * )input;

Discussion

Command can be a complex shell commands.

Parameters
  • command
    The command to execute
  • input
    An optional string to use as standard input for the command

- runCommand: Top

Executes a shell command asynchronously

- ( void )runCommandAsynchronously: ( NSString * )command completion: ( nullable SKShellCommandCompletion )completion;

Discussion

Command can be a complex shell commands.

Parameters
  • command
    The command to execute
  • completion
    An optional completion block
See also

- runCommand: Top

Executes a shell command asynchronously

- ( void )runCommandAsynchronously: ( NSString * )command stdandardInput: ( nullable NSString * )input completion: ( nullable SKShellCommandCompletion )completion;

Discussion

Command can be a complex shell commands.

Parameters
  • command
    The command to execute
  • input
    An optional string to use as standard input for the command
  • completion
    An optional completion block
See also

- runCommand:completion: Top

Executes a shell command synchronously

- ( BOOL )runCommand: ( NSString * )command completion: ( nullable SKShellCommandCompletion )completion;

Discussion

Command can be a complex shell commands.

Parameters
  • command
    The command to execute
  • completion
    An optional completion block

- runCommand:stdandardInput: Top

Executes a shell command synchronously

- ( BOOL )runCommand: ( NSString * )command stdandardInput: ( nullable NSString * )input;

Discussion

Command can be a complex shell commands.

Parameters
  • command
    The command to execute
  • input
    An optional string to use as standard input for the command

- runCommand:stdandardInput:completion: Top

Executes a shell command synchronously

- ( BOOL )runCommand: ( NSString * )command stdandardInput: ( nullable NSString * )input completion: ( nullable SKShellCommandCompletion )completion;

Discussion

Command can be a complex shell commands.

Parameters
  • command
    The command to execute
  • input
    An optional string to use as standard input for the command
  • completion
    An optional completion block

- runCommandAsynchronously: Top

Executes a shell command asynchronously

- ( void )runCommandAsynchronously: ( NSString * )command;

Discussion

Command can be a complex shell commands.

Parameters
  • command
    The command to execute

- runCommandAsynchronously:completion: Top

Executes a shell command asynchronously

- ( void )runCommandAsynchronously: ( NSString * )command completion: ( nullable SKShellCommandCompletion )completion;

Discussion

Command can be a complex shell commands.

Parameters
  • command
    The command to execute
  • completion
    An optional completion block

- runCommandAsynchronously:stdandardInput: Top

Executes a shell command asynchronously

- ( void )runCommandAsynchronously: ( NSString * )command stdandardInput: ( nullable NSString * )input;

Discussion

Command can be a complex shell commands.

Parameters
  • command
    The command to execute
  • input
    An optional string to use as standard input for the command

- runCommandAsynchronously:stdandardInput:completion: Top

Executes a shell command asynchronously

- ( void )runCommandAsynchronously: ( NSString * )command stdandardInput: ( nullable NSString * )input completion: ( nullable SKShellCommandCompletion )completion;

Discussion

Command can be a complex shell commands.

Parameters
  • command
    The command to execute
  • input
    An optional string to use as standard input for the command
  • completion
    An optional completion block

allowPromptHierarchy Top

Enables/Disables prompt hierarchy

@property( atomic, readwrite, assign ) BOOL allowPromptHierarchy;

Discussion

Enabled by default. If disabled, setting prompt parts will have no effect.

See also

colorsEnabled Top

@property( atomic, readwrite, assign ) BOOL colorsEnabled;

Discussion

Enabled by default. Only applicable if the current terminal supports colors.

See also

prompt Top

Used to get/set the current prompt

@property( atomic, readwrite, strong, nullable ) NSString * prompt;

Discussion

If a prompt is set, all messages printed with `SKShell` will be prefixed by the prompt.

promptParts Top

Used to get/set the promt parts

@property( atomic, readwrite, strong, nullable ) NSArray< NSString * > * promptParts;

Discussion

Prompt parts may be set to reflect a hierarchy in the prompt. For instance, setting `@[ @"foo", @"bar" ]` as prompt parts will result in a `[ foo ]> [ bar ]>` prompt.

shell Top

@property( atomic, readonly, nullable ) NSString * shell;

Discussion

Retrieved using the `SHELL` environment variable.

Fields
  • The
    path of the current shell

statusIconsEnabled Top

@property( atomic, readwrite, assign ) BOOL statusIconsEnabled;

Discussion

Enabled by default. Status icons are reprensented by unicode emojis.

See also

supportsColors Top

Set if the current erminal supports color

@property( atomic, readonly ) BOOL supportsColors;

Types

SKShellCommandCompletion Top

Completion block for a shell command

typedef void ( ^ SKShellCommandCompletion )( int status, NSString *stdandardOutput, NSString *standardError );

Parameters
  • status
    The command's exit status
  • stdandardOutput
    The command's standard output, if any
  • standardError
    The command's standard error, if any