From 1e4740a08f45a5e8280b13722801f9e9de669543 Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Fri, 15 Sep 2023 17:12:24 -0500 Subject: [PATCH] refactor: improve template handler on shell expansions --- Misc/Templater.bash | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/Misc/Templater.bash b/Misc/Templater.bash index b851d04..bb12413 100755 --- a/Misc/Templater.bash +++ b/Misc/Templater.bash @@ -52,14 +52,6 @@ log() { # Yes # - # Set debug status depending if a global debug variable has been set to either 1 or 0 - local debug - if [ ${DEBUG} ]; then - debug=${DEBUG} - else - debug=0 - fi - local FORMAT FORMAT="[$(echo_rgb "$(date +%Y-%m-%dT%H:%M:%S)" 180 140 255)]" @@ -166,7 +158,7 @@ _write_to_buffer() { var_handler() { local variable="${1}" local leading_spaces="${2}" - while IFS="\n" read -r line; do + while IFS=$'\n' read -r line; do write_content "${line}" "${leading_spaces}" done <<<"${variable}" } @@ -174,7 +166,7 @@ var_handler() { eval_handler() { local eval_statement="${1}" local leading_spaces="${2}" - while IFS="\n" read -r line; do + while IFS=$'\n' read -r line; do write_content "${line}" "${leading_spaces}" done <<<"$(eval "${eval_statement}")" } @@ -215,7 +207,7 @@ file_handler() { return 1 fi - while IFS="\n" read -r line; do + while IFS=$'\n' read -r line; do write_content "${line}" "${leading_spaces}" done <"${file}" } @@ -330,7 +322,7 @@ read_template() { line_num=1 read_file="${1}" log "info" "Parsing template file \"${read_file}\"" - while IFS="\n" read -r line; do + while IFS=$'\n' read -r line; do # Check for non zero status code if ! parse_template_line "${line}"; then log "error" "Invalid template passed from \"${read_file}\", check line ${line_num}" @@ -389,7 +381,7 @@ usage() { # Yes # printf "Usage: %s\n" \ - "$(basename ${0}) [OPTIONS] + "$(basename "${0}") [OPTIONS] $(arg_required "REQUIRED") $(arg_optional "OPTIONAL")