commit: 74b7514e3de9d0bad82595afcd9ea2c2d936c81f
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Mon Jul 8 05:46:51 2024 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Jul 8 05:46:51 2024 +0000
URL:
https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=74b7514e
Initialise the genfun_bin_true variable lazily
Also, require for true(1) to be executable in order for it to be deemed
usable.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
functions.sh | 58 ++++++++++++++++++++++++++++++++--------------------------
1 file changed, 32 insertions(+), 26 deletions(-)
diff --git a/functions.sh b/functions.sh
index dd4eef8..ad509fa 100644
--- a/functions.sh
+++ b/functions.sh
@@ -725,28 +725,39 @@ _should_throttle()
#
_update_columns()
{
- # Two optimisations are applied. Firstly, the rate at which updates can
- # be performed is throttled to intervals of 5 deciseconds. Secondly, if
- # running on bash then the COLUMNS variable may be gauged, albeit only
- # in situations where doing so can be expected to work reliably; not if
- # in a subshell. Note that executing true(1) is faster than executing
- # stty(1) within a comsub.
- # shellcheck disable=3028,3044
- if _should_throttle 5; then
- test "${genfun_cols}"
- return
- elif [ "$$" = "${BASHPID}" ] && shopt -q checkwinsize; then
- "${genfun_bin_true}"
- set -- 0 "${COLUMNS}"
- else
- # The following use of stty(1) is portable as of POSIX Issue 8.
- genfun_ifs=${IFS}
- IFS=' '
- # shellcheck disable=2046
- set -- $(stty size 2>/dev/null)
- IFS=${genfun_ifs}
+ # shellcheck disable=3044
+ if [ "${BASH}" ] && shopt -q checkwinsize; then
+ genfun_bin_true=$(whenceforth -x true)
fi
- [ "$#" -eq 2 ] && is_int "$2" && [ "$2" -gt 0 ] && genfun_cols=$2
+
+ _update_columns()
+ {
+ # Two optimisations are applied. Firstly, the rate at which
+ # updates can be performed is throttled to intervals of 5
+ # deciseconds. Secondly, if running on bash then the COLUMNS
+ # variable may be gauged, albeit only in situations where doing
+ # so can be expected to work reliably; it is an unreliable
+ # method where operating from a subshell. Note that executing
+ # true(1) is faster than executing stty(1) within a comsub.
+ # shellcheck disable=3028
+ if _should_throttle 5; then
+ test "${genfun_cols}"
+ return
+ elif [ "${genfun_bin_true}" ] && [ "$$" = "${BASHPID}" ]; then
+ "${genfun_bin_true}"
+ set -- 0 "${COLUMNS}"
+ else
+ # This use of stty(1) is portable as of POSIX-1.2024.
+ genfun_ifs=${IFS}
+ IFS=' '
+ # shellcheck disable=2046
+ set -- $(stty size 2>/dev/null)
+ IFS=${genfun_ifs}
+ fi
+ [ "$#" -eq 2 ] && is_int "$2" && [ "$2" -gt 0 ] &&
genfun_cols=$2
+ }
+
+ _update_columns
}
#
@@ -872,11 +883,6 @@ fi
genfun_newline='
'
-# Store the path to the true binary. It is potentially used by _update_columns.
-if [ "${BASH}" ]; then
- genfun_bin_true=$(whenceforth true)
-fi
-
# The GENFUN_MODULES variable acts as a means of selecting modules, which are
# merely optional collections of functions. If unset then set it now.
if [ ! "${GENFUN_MODULES+set}" ]; then