diff options
author | 2024-08-02 18:31:16 +0100 | |
---|---|---|
committer | 2024-08-02 18:31:16 +0100 | |
commit | 81d81d22d039f3ed966df31c61d8ef5b664f1c4d (patch) | |
tree | a5a32421303b9815d0111076ae86aee44896f350 | |
parent | Adhere to the Allman style for _select_by_mtime() (diff) | |
download | gentoo-functions-81d81d22d039f3ed966df31c61d8ef5b664f1c4d.tar.gz gentoo-functions-81d81d22d039f3ed966df31c61d8ef5b664f1c4d.tar.bz2 gentoo-functions-81d81d22d039f3ed966df31c61d8ef5b664f1c4d.zip |
Jettison the bash-specific hr() implementation
Testing the BASH variable for non-emptiness is an inadequate pretext for
activating the bash-optimised code path. Instead, the test would have to
be implemented like so ...
if ! case ${BASH_COMPAT} in 3?|4[012]) false ;; esac && _has_bash 4 3
then
...
fi
Given that hr() is not expected to be called often, and that the sh code
was already improved by employing a divide-by-8 strategy, I don't
consider it to be worth the trouble.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
-rw-r--r-- | functions.sh | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/functions.sh b/functions.sh index 5ef96ae..b7e6c1d 100644 --- a/functions.sh +++ b/functions.sh @@ -175,21 +175,15 @@ hr() fi char=${1--} char=${char%"${char#?}"} - if [ "${BASH}" ]; then - # shellcheck disable=3045 - printf -v hr '%*s' "${length}" '' - eval 'printf %s\\n "${hr//?/"$char"}"' - else - i=0 - while [ "$(( i += 8 ))" -le "${length}" ]; do - hr=${hr}${char}${char}${char}${char}${char}${char}${char}${char} - done - i=${#hr} - while [ "$(( i += 1 ))" -le "${length}" ]; do - hr=${hr}${char} - done - printf '%s\n' "${hr}" - fi + i=0 + while [ "$(( i += 8 ))" -le "${length}" ]; do + hr=${hr}${char}${char}${char}${char}${char}${char}${char}${char} + done + i=${#hr} + while [ "$(( i += 1 ))" -le "${length}" ]; do + hr=${hr}${char} + done + printf '%s\n' "${hr}" } # |