From f57eb1b80d3015c6ffce59eb42ed9d2ce5f2c17f Mon Sep 17 00:00:00 2001 From: rwxrob Date: Fri, 27 Aug 2021 13:11:03 -0400 Subject: [PATCH] Fix position of `_read_config` and `_initialize` --- cmd | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cmd b/cmd index 55fccc5..d589ed7 100755 --- a/cmd +++ b/cmd @@ -13,6 +13,10 @@ set -e declare -A HELP declare -A CONFIG +_initialize() { + : # put initialization code here +} + HELP[main]=' # Bash Template Command @@ -35,9 +39,12 @@ tab completion, but will still be there. The `readme` command (which generates this `README.md` file is a good candidate for this.) Be sure to check out the builtin and utility functions. Some of these - can be removed as well if you really want. +The `_initialize` function is meant to put initialization code at the +beginning of the script to be found easily even though it is called at +the bottom of the script (as bash requires). + ## Naming Conventions * Name repos containing single bash commands with `cmd-` @@ -408,6 +415,9 @@ if [[ -n $COMP_LINE ]]; then exit fi +_config_read +_initialize + for c in "${COMMANDS[@]}"; do if [[ $c == "$EXE" ]]; then "command_$EXE" "$@" @@ -415,8 +425,6 @@ for c in "${COMMANDS[@]}"; do fi done -_config_read - if [[ -n "$1" ]]; then declare cmd="$1"; shift for c in "${COMMANDS[@]}"; do