aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKylie McClain <kylie@somas.is>2020-07-07 08:24:02 -0400
committerKylie McClain <kylie@somas.is>2020-07-07 08:24:02 -0400
commit777fa90f703ee0c5caffa703428bfa25920ec059 (patch)
treef94ba3ea723e2df8656c6a11c97d123959dbb7ba
parent551f68943778e8eb8da580044b5b419649f27680 (diff)
downloadidioms-777fa90f703ee0c5caffa703428bfa25920ec059.tar.gz
idioms-777fa90f703ee0c5caffa703428bfa25920ec059.tar.xz
idioms-777fa90f703ee0c5caffa703428bfa25920ec059.zip
idioms.sh: add a variable to prevent loading the script unnecessarily
-rw-r--r--idioms.3.adoc5
-rw-r--r--idioms.sh.in5
2 files changed, 9 insertions, 1 deletions
diff --git a/idioms.3.adoc b/idioms.3.adoc
index a5f1178..3b6dee3 100644
--- a/idioms.3.adoc
+++ b/idioms.3.adoc
@@ -37,6 +37,11 @@ Additionally, these variables may not be modified after the *idioms* script is s
left undefined, since setting color variables by default would cause a small startup delay due
to all the invocations to tput(1).
+*_idioms_loaded*::
+ Indicates that idioms is already loaded into the runtime, so as to avoid wasting time
+ redeclaring things that have already been set. This is set at the end of the script.
+ You shouldn't need to mess with this variable.
+
== Colors
One feature of *idioms* is providing access to text formatting codes through variables that degrade
diff --git a/idioms.sh.in b/idioms.sh.in
index 38868b4..52c1d20 100644
--- a/idioms.sh.in
+++ b/idioms.sh.in
@@ -4,6 +4,8 @@
# SC2034: Allow unused text_* variables.
# shellcheck disable=SC2034,SC2059
+[ "${_idioms_loaded}" = 'true' ] && return
+
# See <https://no-color.org/>.
: "${NO_COLOR:=}"
@@ -197,7 +199,8 @@ _idioms_setup_colors() {
}
: "${_idioms_colors:=false}"
-readonly _idioms_colors
_idioms_setup_colors
+: "${_idioms_loaded:=true}"
+readonly _idioms_loaded