From 63aa43f6b7d051f46ba5bc8930f750b8d471c7c9 Mon Sep 17 00:00:00 2001 From: Sandor Semsey Date: Tue, 28 May 2024 00:33:09 +0200 Subject: [PATCH] lib/loader: add support for local loader --- docs/lib/_loader.md | 3 +++ lib/_loader.sh | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/docs/lib/_loader.md b/docs/lib/_loader.md index a817818..67798d8 100644 --- a/docs/lib/_loader.md +++ b/docs/lib/_loader.md @@ -3,6 +3,9 @@ Helper to bootstrap libraries. This file sources all library files so functions will be defined and available. Basically, you need to source this file in any script where you want to use library functions. +Also, you can extend this loader to load your local library files too! +Create your loader script that sources the local libraries and just point `ES_SHELL_LOADER_LOCAL` environment variable to it (e.g. `ES_SHELL_LOADER_LOCAL=$HOME/.local/lib/myloader.sh`), and they will be sourced. + **Usage in scripts** ```bash diff --git a/lib/_loader.sh b/lib/_loader.sh index a53555a..87b4cee 100644 --- a/lib/_loader.sh +++ b/lib/_loader.sh @@ -22,3 +22,8 @@ base_dir=$(cd "$(dirname "${path_self}")" >/dev/null 2>&1 && pwd) . "${base_dir}/ssh.sh" . "${base_dir}/text.sh" . "${base_dir}/ui.sh" + +if [[ -r "${ES_SHELL_LOADER_LOCAL:-}" ]]; then + # shellcheck disable=SC1090 + . "${ES_SHELL_LOADER_LOCAL}" +fi