commit: 81d81d22d039f3ed966df31c61d8ef5b664f1c4d
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Fri Aug 2 17:31:16 2024 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Aug 2 17:31:16 2024 +0000
URL:
https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=81d81d22
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 <AT> plushkava.net>
functions.sh | 24 +++++++++---------------
1 file 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}"
}
#