From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id B629C159C9B for ; Fri, 2 Aug 2024 23:14:15 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 786E8E2A43; Fri, 2 Aug 2024 23:14:14 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 5C326E2A45 for ; Fri, 2 Aug 2024 23:14:14 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 6A87F34300D for ; Fri, 2 Aug 2024 23:14:13 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id A7D9B1E7E for ; Fri, 2 Aug 2024 23:14:11 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1720417611.74b7514e3de9d0bad82595afcd9ea2c2d936c81f.sam@gentoo> Subject: [gentoo-commits] proj/gentoo-functions:master commit in: / X-VCS-Repository: proj/gentoo-functions X-VCS-Files: functions.sh X-VCS-Directories: / X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: 74b7514e3de9d0bad82595afcd9ea2c2d936c81f X-VCS-Branch: master Date: Fri, 2 Aug 2024 23:14:11 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 2bc5c949-64db-4845-a939-9191394a64d5 X-Archives-Hash: aeb482b2c25d1832d93f8aa18d152077 commit: 74b7514e3de9d0bad82595afcd9ea2c2d936c81f Author: Kerin Millar plushkava net> AuthorDate: Mon Jul 8 05:46:51 2024 +0000 Commit: Sam James gentoo 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 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