Functions

The functions are grouped into two sets, the base functions, and the extended functions.

Base Functions

These functions are available both in the base and extended versions.

When extra arguments are passed to these functions, those arguments become positional parameters when the referred script is loaded.

  • load()

    Unconditionally loads a file even if it’s already been flagged.

    Usage: load <complete|partial_path> [<args>]

  • include()

    Also loads and flags a file like load() but only if the file has not yet been included or flagged.

    Usage: include <complete|partial_path> [<args>]

  • call()

    This function acts the same as load() but it loads the file in a separated environment (subshell). This is useful if a user wants to make a co-shell-script do its job without affecting the environment of the caller. The function also returns the exit code of the subshell after the subshell finishes executing. Also loads and flags a file like load() but only if the file has not yet been included or flagged.

    Usage: call <complete|partial_path> [<args>]

  • loader_addpath()

    Accepts one or more arguments of directory paths and adds them to the list of searchable directories that will be used by load(), include() and call() when searching for files that are specified through partial paths.

    Usage: loader_addpath <absolute|relative_path> ...

  • loader_flag()

    Marks the specified path to a file as if it’s already been loaded with load(), include() or call(). Note that the file referred by path does not need to exist. This function is mostly useful like when you want to mark a loaded script that has not been loaded by any of the loading functions like the startup or main script that loads the implementation script.

    This function can accept any form of path (may it be absolute or relative) but note that the function always converts a path to its clean absolute form.

    Usage: loader_flag <path> [<args>]

  • loader_reset()

    This function acts depending on the argument that is passed to it.

    Usage: loader_reset [flags|paths]

    flags – Clear the flags of the loaded files
    paths – Clear the list of search paths

    The function clears both if no argument is passed.

  • loader_finish()

    This will unload loader from shellspace. The function requires no argument.

Extended Functions

These functions are only available in the extended version. They basically act similar to their simpler counterparts, only that they are also capable of targetting multiple files at once.

These are the forms in which these functions can be used:

  • loadx|includex|callx <plain_path> [<args>]

    If the path does not contain * or ?, it is considered as a plain path.

    The function just acts the same as its simpler version in this case.

  • loadx|includex|callx <[prefix_path/]glob_pattern> [<args>]

    If the expression contains the glob characters ? and/or *, it will be considered as a glob pattern.

    Bracket characters [ and ] are also glob characters but it is not easy to tell if those are quoted or not in scripts, and may sometimes just cause confusion since brackets may also represent valid characters in a file’s name. The other glob characters ? and * are an exception since they can sometimes be invalid filename characters. It is also not much sensible for them to be used in naming scripts, unlike brackets.

    If it is implied that [ or ] is a glob character, we can just use the -name or the -iname option.

  • loadx|includex|callx -name|-iname|-regex|-iregex <[prefix_path/]pattern|expression> [<args>]

    If the first argument is one of the options -name, -iname, -regex, and -iregex, the function will interpret the next string as a pattern or expression with respect to that option.

    -name   – argument is a glob pattern
    -iname  – argument is a glob pattern and is not case sensitive
    -regex  – argument is a regular expression
    -iregex – argument is a regular expression and is not case sensitive

Next Page: Usage Examples