Skip to content

shellm.sh

Timothée Mazzucotelli edited this page Sep 27, 2018 · 4 revisions

Environment Variables

  • SHELLM_TIME: If set, shellm will measure the loading time for each library file sourced in the current process. You will then be able to print this information with the command shellm-print-loadtime.
  • __SHELLM_LIBSTACK: The current stack of sources being loaded.
  • SHELLM_SOURCES: The list of sources already loaded in the current shell process.
  • LIBPATH: The colon-separated list of directories in which to search for library files or packages.

Files

  • /tmp/shellm-time.PID: Data file used to store loading time per source for given process.

Functions

shellm <COMMAND> [ARGS]

Execute a shellm command, be it a function or a script.

Arguments

  • COMMAND: The name of an existing shellm command.

Return codes

  • ?: The return code of the invoked command.
  • 1: Unkown command.

__shellm_locate <FILEPATH>

Locate a library file in LIBPATH.

Arguments

  • FILEPATH: The relative file path.

Return codes

  • 0: File found.
  • 1: File not found.

__shellm_has_source <LIBFILE>

Check if LIBFILE is already in shellm sources.

Arguments

  • LIBFILE: The file absolute path.

Return codes

  • 0: Source is loaded.
  • 1: Source is not loaded.

__shellm_add_source <LIBFILE>

Append source LIBFILE to shellm sources.

Arguments

  • LIBFILE: The file absolute path.

__shellm_libstack_push <LIBFILE>

Append source LIBFILE to the souce stack.

Arguments

  • LIBFILE: The file absolute path.

__shellm_libstack_pop

Remove the last item of the source stack.

Arguments

  • NAME: The source name, e.g. shellm/home/lib/home.sh.

__shellm_time_set_delta

Set the time delta sum variable to 0.


__shellm_time_unset_delta

Unset the time delta sum variable.


__shellm_time_now

Return a timestamp (seconds since Epoch plus nanoseconds).


__shellm_time_start

Start the timer (store now in parent local start variable).


__shellm_time_end <NAME>

End the timer and update the time delta sum.

Write-append the time delta for the given source in this process' data file.

Arguments

  • NAME: The source name, e.g. shellm/home/lib/home.sh.

shellm-print-loadtime [PID]

Pretty-print the loading time for each source for a given shell process.

Arguments

  • PID: The PID of a shell process (default to $$).

Return codes

  • 1: Data file for the given PID does not exist.

See also

  • The SHELLM_TIME environment variable.

__shellm_source <NAME> <ABS_PATH>

Load source if not loaded, measure load time, warn when errors.

This function first sets the time delta sum to 0. Then it checks if the given source is already loaded or not. If not, it adds it in the sources list and stack, then start the timer. It sources it, end the timer, and remove it from the stack. If something went wrong while loading it, it echoes an error with references: original script, source file, current stack.

Arguments

  • NAME: The source name, e.g. shellm/home/lib/home.sh.
  • ABS_PATH: The library file absolute path.

Return codes

  • 0: Everything OK.
  • 1: Error when sourcing file.

shellm-source <NAME>

Locate a source or package, and source it in the current shell process.

If NAME is a package, searches for every file in a lib directory and sources each one of them.

Arguments

  • NAME: The source or package name, e.g. shellm/home.

Return codes

  • 1: Source or package not found.

Wiki page generated with shellman.