Options
All
  • Public
  • Public/Protected
  • All
Menu

cli-driver

Index

Type aliases

ExecCallback

ExecCallback: function

Type declaration

    • (code: number, stdout: string, stderr: string): any
    • Parameters

      • code: number
      • stdout: string
      • stderr: string

      Returns any

ShellArray

ShellArray: string[] & ShellReturnValue

ShellString

ShellString: string & ShellReturnValue

TestOptions

TestOptions: "-b" | "-c" | "-d" | "-e" | "-f" | "-L" | "-p" | "-S"

TouchOptionsLiteral

TouchOptionsLiteral: "-a" | "-c" | "-m" | "-d" | "-r"

Variables

Const config

config: ShellConfig

The shelljs configuration.

Const env

env: object

Object containing environment variables (both getter and setter). Shortcut to process.env.

Type declaration

  • [key: string]: string

Functions

cat

  • Returns a string containing the given file, or a concatenated string containing the files if more than one file is given (a new line character is introduced between each file). Wildcard * accepted.

    Parameters

    • Rest ...files: Array<string | string[]>

    Returns ShellString

    A string containing the given file, or a concatenated string containing the files if more than one file is given (a new line character is introduced between each file).

cd

  • cd(dir?: string): void
  • Changes to directory dir for the duration of the script. Changes to home directory if no argument is supplied.

    Parameters

    • Optional dir: string

      Directory to change in.

    Returns void

chmod

  • chmod(octalMode: number, file: string): void
  • chmod(options: string, octalMode: number, file: string): void
  • chmod(mode: string, file: string): void
  • chmod(options: string, mode: string, file: string): void
  • Alters the permissions of a file or directory by either specifying the absolute permissions in octal form or expressing the changes in symbols. This command tries to mimic the POSIX behavior as much as possible. Notable exceptions:

    • In symbolic modes, 'a-r' and '-r' are identical. No consideration is given to the umask.
    • There is no "quiet" option since default behavior is to run silent.

    Parameters

    • octalMode: number

      The access mode. Octal.

    • file: string

      The file to use.

    Returns void

  • Alters the permissions of a file or directory by either specifying the absolute permissions in octal form or expressing the changes in symbols. This command tries to mimic the POSIX behavior as much as possible. Notable exceptions:

    • In symbolic modes, 'a-r' and '-r' are identical. No consideration is given to the umask.
    • There is no "quiet" option since default behavior is to run silent.

    Parameters

    • options: string

      Available options: -v (output a diagnostic for every file processed), -c (like -v but report only when a change is made), -R (change files and directories recursively)

    • octalMode: number

      The access mode. Octal.

    • file: string

      The file to use.

    Returns void

  • Alters the permissions of a file or directory by either specifying the absolute permissions in octal form or expressing the changes in symbols. This command tries to mimic the POSIX behavior as much as possible. Notable exceptions:

    • In symbolic modes, 'a-r' and '-r' are identical. No consideration is given to the umask.
    • There is no "quiet" option since default behavior is to run silent.

    Parameters

    • mode: string

      The access mode. Can be an octal string or a symbolic mode string.

    • file: string

      The file to use.

    Returns void

  • Alters the permissions of a file or directory by either specifying the absolute permissions in octal form or expressing the changes in symbols. This command tries to mimic the POSIX behavior as much as possible. Notable exceptions:

    • In symbolic modes, 'a-r' and '-r' are identical. No consideration is given to the umask.
    • There is no "quiet" option since default behavior is to run silent.

    Parameters

    • options: string

      Available options: -v (output a diagnostic for every file processed), -c (like -v but report only when a change is made), -R (change files and directories recursively)

    • mode: string

      The access mode. Can be an octal string or a symbolic mode string.

    • file: string

      The file to use.

    Returns void

cp

  • cp(source: string | string[], dest: string): void
  • cp(options: string, source: string | string[], dest: string): void
  • Copies files. The wildcard * is accepted.

    Parameters

    • source: string | string[]

      The source.

    • dest: string

      The destination.

    Returns void

  • Copies files. The wildcard * is accepted.

    Parameters

    • options: string

      Available options: -f: force (default behavior) -n: no-clobber -u: only copy if source is newer than dest -r, -R: recursive -L: follow symlinks -P: don't follow symlinks

    • source: string | string[]

      The source.

    • dest: string

      The destination.

    Returns void

dirs

  • Clears the directory stack by deleting all of the elements.

    Parameters

    • options: "-c"

      Clears the directory stack by deleting all of the elements.

    Returns ShellArray

    Returns an array of paths in the stack, or a single path if +N or -N was specified.

  • Display the list of currently remembered directories. Returns an array of paths in the stack, or a single path if +N or -N was specified.

    Parameters

    • options: "+N"

      Displays the Nth directory (counting from the left of the list printed by dirs when invoked without options), starting with zero.

    Returns ShellString

    Returns an array of paths in the stack, or a single path if +N or -N was specified.

  • Display the list of currently remembered directories. Returns an array of paths in the stack, or a single path if +N or -N was specified.

    Parameters

    • options: "-N"

      Displays the Nth directory (counting from the right of the list printed by dirs when invoked without options), starting with zero.

    Returns ShellString

    Returns an array of paths in the stack, or a single path if +N or -N was specified.

  • Display the list of currently remembered directories. Returns an array of paths in the stack, or a single path if +N or -N was specified.

    Parameters

    • options: string

      Available options: -c, -N, +N. You can only use those.

    Returns any

    Returns an array of paths in the stack, or a single path if +N or -N was specified.

echo

  • Prints string to stdout, and returns string with additional utility methods like .to().

    Parameters

    • Rest ...text: string[]

    Returns ShellString

    Returns the string that was passed as argument.

  • Prints string to stdout, and returns string with additional utility methods like .to().

    Parameters

    • options: string

      Available options: -e: interpret backslash escapes (default) -n: remove trailing newline from output

    • Rest ...text: string[]

    Returns ShellString

    Returns the string that was passed as argument.

error

  • Tests if error occurred in the last command.

    Returns ShellString

    Returns null if no error occurred, otherwise returns string explaining the error

exec

  • Executes the given command synchronously.

    Parameters

    • command: string

      The command to execute.

    Returns ExecOutputReturnValue

    Returns an object containing the return code and output as string.

  • Executes the given command synchronously.

    Parameters

    • command: string

      The command to execute.

    • options: ExecOptions

      Silence and synchronous options.

    Returns ExecOutputReturnValue | ChildProcess

    Returns an object containing the return code and output as string, or if {async:true} was passed, a ChildProcess.

  • Executes the given command synchronously.

    Parameters

    • command: string

      The command to execute.

    • options: ExecOptions

      Silence and synchronous options.

    • callback: ExecCallback

      Receives code and output asynchronously.

    Returns ChildProcess

  • Executes the given command synchronously.

    Parameters

    • command: string

      The command to execute.

    • callback: ExecCallback

      Receives code and output asynchronously.

    Returns ChildProcess

exit

  • exit(code: number): void
  • Exits the current process with the given exit code.

    Parameters

    • code: number

      The exit code.

    Returns void

find

  • find(...path: Array<string | string[]>): ShellArray
  • Returns array of all files (however deep) in the given paths.

    Parameters

    • Rest ...path: Array<string | string[]>

    Returns ShellArray

    An array of all files (however deep) in the given path(s).

grep

  • grep(regex_filter: string | RegExp, ...files: Array<string | string[]>): ShellString
  • grep(options: string, regex_filter: string | RegExp, ...files: Array<string | string[]>): ShellString
  • Reads input string from given files and returns a string containing all lines of the file that match the given regex_filter. Wildcard * accepted.

    Parameters

    • regex_filter: string | RegExp

      The regular expression to use.

    • Rest ...files: Array<string | string[]>

    Returns ShellString

    Returns a string containing all lines of the file that match the given regex_filter.

  • Reads input string from given files and returns a string containing all lines of the file that match the given regex_filter. Wildcard * accepted.

    Parameters

    • options: string

      Available options: -v (Inverse the sense of the regex and print the lines not matching the criteria.) -l: Print only filenames of matching files

    • regex_filter: string | RegExp

      The regular expression to use.

    • Rest ...files: Array<string | string[]>

    Returns ShellString

    Returns a string containing all lines of the file that match the given regex_filter.

head

  • Read the start of a file.

    Parameters

    • Rest ...files: Array<string | string[]>

    Returns ShellString

  • Read the start of a file.

    Parameters

    • options: HeadOptions
    • Rest ...files: Array<string | string[]>

    Returns ShellString

ln

  • ln(source: string, dest: string): void
  • ln(options: string, source: string, dest: string): void
  • Links source to dest. Use -f to force the link, should dest already exist.

    Parameters

    • source: string

      The source.

    • dest: string

      The destination.

    Returns void

  • Links source to dest. Use -f to force the link, should dest already exist.

    Parameters

    • options: string

      Available options: s (symlink), f (force)

    • source: string

      The source.

    • dest: string

      The destination.

    Returns void

ls

  • ls(...paths: Array<string | string[]>): ShellArray
  • ls(options: string, ...paths: Array<string | string[]>): ShellArray
  • Returns array of files in the given path, or in current directory if no path provided.

    Parameters

    • Rest ...paths: Array<string | string[]>

    Returns ShellArray

    An array of files in the given path(s).

  • Returns array of files in the given path, or in current directory if no path provided.

    Parameters

    • options: string

      Available options: -R: recursive -A: all files (include files beginning with ., except for . and ..) -L: follow symlinks -d: list directories themselves, not their contents -l: list objects representing each file, each with fields containing ls -l output fields. See fs.Stats for more info

    • Rest ...paths: Array<string | string[]>

    Returns ShellArray

    An array of files in the given path(s).

mkdir

  • mkdir(...dir: Array<string | string[]>): void
  • mkdir(options: string, ...dir: Array<string | string[]>): void
  • Creates directories.

    Parameters

    • Rest ...dir: Array<string | string[]>

    Returns void

  • Creates directories.

    Parameters

    • options: string

      Available options: p (full paths, will create intermediate dirs if necessary)

    • Rest ...dir: Array<string | string[]>

    Returns void

mv

  • mv(source: string | string[], dest: string): void
  • mv(options: string, source: string | string[], dest: string): void
  • Moves files. The wildcard * is accepted.

    Parameters

    • source: string | string[]

      The source.

    • dest: string

      The destination.

    Returns void

  • Moves files. The wildcard * is accepted.

    Parameters

    • options: string

      Available options: -f: force (default behavior) -n: no-clobber

    • source: string | string[]

      The source.

    • dest: string

      The destination.

    Returns void

popd

  • When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack.

    Parameters

    • dir: "+N"

      Removes the Nth directory (counting from the left of the list printed by dirs), starting with zero.

    Returns ShellArray

    Returns an array of paths in the stack.

  • When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack.

    Returns ShellArray

    Returns an array of paths in the stack.

  • When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack.

    Parameters

    • dir: "-N"

      Removes the Nth directory (counting from the right of the list printed by dirs), starting with zero.

    Returns ShellArray

    Returns an array of paths in the stack.

  • When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack.

    Parameters

    • dir: string

      You can only use -N and +N.

    Returns ShellArray

    Returns an array of paths in the stack.

  • When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack.

    Parameters

    • options: string

      Available options: -n (Suppresses the normal change of directory when removing directories from the stack, so that only the stack is manipulated) -q: Supresses output to the console.

    • dir: "+N"

      Removes the Nth directory (counting from the left of the list printed by dirs), starting with zero.

    Returns ShellArray

    Returns an array of paths in the stack.

  • When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack.

    Parameters

    • options: string

      Available options: -n (Suppresses the normal change of directory when removing directories from the stack, so that only the stack is manipulated) -q: Supresses output to the console.

    • dir: "-N"

      Removes the Nth directory (counting from the right of the list printed by dirs), starting with zero.

    Returns ShellArray

    Returns an array of paths in the stack.

  • When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack.

    Parameters

    • options: string

      Available options: -n (Suppresses the normal change of directory when removing directories from the stack, so that only the stack is manipulated) -q: Supresses output to the console.

    • dir: string

      You can only use -N and +N.

    Returns ShellArray

    Returns an array of paths in the stack.

pushd

  • Save the current directory on the top of the directory stack and then cd to dir. With no arguments, pushd exchanges the top two directories. Returns an array of paths in the stack.

    Parameters

    • dir: "+N"

      Brings the Nth directory (counting from the left of the list printed by dirs, starting with zero) to the top of the list by rotating the stack.

    Returns ShellArray

    Returns an array of paths in the stack.

  • Save the current directory on the top of the directory stack and then cd to dir. With no arguments, pushd exchanges the top two directories. Returns an array of paths in the stack.

    Parameters

    • dir: "-N"

      Brings the Nth directory (counting from the right of the list printed by dirs, starting with zero) to the top of the list by rotating the stack.

    Returns ShellArray

    Returns an array of paths in the stack.

  • Save the current directory on the top of the directory stack and then cd to dir. With no arguments, pushd exchanges the top two directories. Returns an array of paths in the stack.

    Parameters

    • dir: string

      Makes the current working directory be the top of the stack, and then executes the equivalent of cd dir.

    Returns ShellArray

    Returns an array of paths in the stack.

  • Save the current directory on the top of the directory stack and then cd to dir. With no arguments, pushd exchanges the top two directories. Returns an array of paths in the stack.

    Parameters

    • options: string

      Available options: -n (Suppresses the normal change of directory when adding directories to the stack, so that only the stack is manipulated) -q: Supresses output to the console.

    • dir: "+N"

      Brings the Nth directory (counting from the left of the list printed by dirs, starting with zero) to the top of the list by rotating the stack.

    Returns ShellArray

    Returns an array of paths in the stack.

  • Save the current directory on the top of the directory stack and then cd to dir. With no arguments, pushd exchanges the top two directories. Returns an array of paths in the stack.

    Parameters

    • options: string

      Available options: -n (Suppresses the normal change of directory when adding directories to the stack, so that only the stack is manipulated)

    • dir: "-N"

      Brings the Nth directory (counting from the right of the list printed by dirs, starting with zero) to the top of the list by rotating the stack.

    Returns ShellArray

    Returns an array of paths in the stack.

  • Save the current directory on the top of the directory stack and then cd to dir. With no arguments, pushd exchanges the top two directories. Returns an array of paths in the stack.

    Parameters

    • options: string

      Available options: -n (Suppresses the normal change of directory when adding directories to the stack, so that only the stack is manipulated)

    • dir: string

      Makes the current working directory be the top of the stack, and then executes the equivalent of cd dir.

    Returns ShellArray

    Returns an array of paths in the stack.

pwd

  • Returns the current directory.

    Returns ShellString

    The current directory.

rm

  • rm(...files: Array<string | string[]>): void
  • rm(options: string, ...files: Array<string | string[]>): void
  • Removes files. The wildcard * is accepted.

    Parameters

    • Rest ...files: Array<string | string[]>

    Returns void

  • Removes files. The wildcard * is accepted.

    Parameters

    • options: string

      Available options: -f (force), -r, -R (recursive)

    • Rest ...files: Array<string | string[]>

    Returns void

sed

  • sed(searchRegex: string | RegExp, replacement: string, file: string): ShellString
  • sed(options: string, searchRegex: string | RegExp, replacement: string, file: string): ShellString
  • Reads an input string from file and performs a JavaScript replace() on the input using the given search regex and replacement string or function. Returns the new string after replacement.

    Parameters

    • searchRegex: string | RegExp

      The regular expression to use for search.

    • replacement: string

      The replacement.

    • file: string

      The file to process.

    Returns ShellString

    The new string after replacement.

  • Reads an input string from file and performs a JavaScript replace() on the input using the given search regex and replacement string or function. Returns the new string after replacement.

    Parameters

    • options: string

      Available options: -i (Replace contents of 'file' in-place. Note that no backups will be created!)

    • searchRegex: string | RegExp

      The regular expression to use for search.

    • replacement: string

      The replacement.

    • file: string

      The file to process.

    Returns ShellString

    The new string after replacement.

set

  • set(options: string): void
  • Sets global configuration variables

    Parameters

    • options: string

      Available options: +/-e: exit upon error (config.fatal), +/-v: verbose: show all commands (config.verbose), +/-f: disable filename expansion (globbing)

    Returns void

sort

  • sort(...files: Array<string | string[]>): ShellString
  • sort(options: string, ...files: Array<string | string[]>): ShellString
  • Return the contents of the files, sorted line-by-line. Sorting multiple files mixes their content (just as unix sort does).

    Parameters

    • Rest ...files: Array<string | string[]>

    Returns ShellString

  • Return the contents of the files, sorted line-by-line. Sorting multiple files mixes their content (just as unix sort does).

    Parameters

    • options: string

      Available options: -r: Reverse the results -n: Compare according to numerical value

    • Rest ...files: Array<string | string[]>

    Returns ShellString

tail

  • Read the end of a file.

    Parameters

    • Rest ...files: Array<string | string[]>

    Returns ShellString

  • Read the end of a file.

    Parameters

    • options: TailOptions
    • Rest ...files: Array<string | string[]>

    Returns ShellString

tempdir

  • Searches and returns string containing a writeable, platform-dependent temporary directory. Follows Python's tempfile algorithm.

    Returns ShellString

    The temp file path.

test

  • Evaluates expression using the available primaries and returns corresponding value.

    Parameters

    • option: TestOptions

      '-b': true if path is a block device; '-c': true if path is a character device; '-d': true if path is a directory; '-e': true if path exists; '-f': true if path is a regular file; '-L': true if path is a symboilc link; '-p': true if path is a pipe (FIFO); '-S': true if path is a socket

    • path: string

      The path.

    Returns boolean

    See option parameter.

touch

  • touch(...files: string[]): void
  • touch(files: string[]): void
  • touch(options: TouchOptionsLiteral, ...files: Array<string | string[]>): void
  • touch(options: TouchOptionsArray, ...files: Array<string | string[]>): void
  • Parameters

    • Rest ...files: string[]

    Returns void

  • Parameters

    • files: string[]

    Returns void

  • Parameters

    Returns void

  • Parameters

    Returns void

uniq

  • uniq(input: string, output?: string): ShellString
  • uniq(options: string, input: string, output?: string): ShellString
  • Filter adjacent matching lines from input.

    Parameters

    • input: string
    • Optional output: string

    Returns ShellString

  • Filter adjacent matching lines from input.

    Parameters

    • options: string

      Available options: -i: Ignore case while comparing -c: Prefix lines by the number of occurrences -d: Only print duplicate lines, one for each group of identical lines

    • input: string
    • Optional output: string

    Returns ShellString

which

  • Searches for command in the system's PATH. On Windows looks for .exe, .cmd, and .bat extensions.

    Parameters

    • command: string

      The command to search for.

    Returns ShellString

    Returns string containing the absolute path to the command.

Generated using TypeDoc