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 8E51315800F for ; Sat, 11 Feb 2023 01:43:19 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 4D373E0718; Sat, 11 Feb 2023 01:43:18 +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 2F803E0718 for ; Sat, 11 Feb 2023 01:43:18 +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 2593B335D58 for ; Sat, 11 Feb 2023 01:43:17 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 4A6B2891 for ; Sat, 11 Feb 2023 01:43:15 +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: <1676078967.9b3c0592552ecba127fd872b8ba168efea0fdaaf.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: 9b3c0592552ecba127fd872b8ba168efea0fdaaf X-VCS-Branch: master Date: Sat, 11 Feb 2023 01:43:15 +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: 5cb1fa55-9fec-4091-b9d4-09f759a68491 X-Archives-Hash: 349de71fb057678b084f37d781e42217 commit: 9b3c0592552ecba127fd872b8ba168efea0fdaaf Author: Kerin Millar plushkava net> AuthorDate: Fri Feb 10 23:46:10 2023 +0000 Commit: Sam James gentoo org> CommitDate: Sat Feb 11 01:29:27 2023 +0000 URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=9b3c0592 Ensure that COLUMNS is set in the case that /bin/sh is bash To reasonably ensure that the COLUMNS variable is set requires for three conditions to be fulfilled. Firstly, the version of bash must be at least 4.3. Secondly, the checkwinsize shopt must be enabled (since 5.0, it is enabled by default). Thirdly, an external command must be executed. Better fulfil these conditions by checking whether the shell appears to be bash and, should it appear to be, enabling checkwinsize before executing /bin/true. Determining the number of columns in this way is preferable to falling back to the method of attempting to use stty(1). Signed-off-by: Kerin Millar plushkava.net> Signed-off-by: Sam James gentoo.org> functions.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/functions.sh b/functions.sh index 9ab8d0c..241f238 100644 --- a/functions.sh +++ b/functions.sh @@ -453,8 +453,15 @@ for arg in "$@" ; do done # Define COLS and ENDCOL so that eend can line up the [ ok ]. +if [ -n "${BASH}" ] && shopt -s checkwinsize 2>/dev/null; then + # As is documented, running an external command will cause bash to set + # the COLUMNS variable. This technique is effective for >=4.3, though + # it requires for the checkwinsize shopt to be enabled. By default, it + # is only enabled for >=5.0. + /bin/true +fi if is_int "${COLUMNS}" && [ "${COLUMNS}" -gt 0 ]; then - # The value of COLUMNS was likely set by a shell such as bash. Trust it. + # The value of COLUMNS was likely set by a shell such as bash or mksh. COLS=${COLUMNS} else # Try to use stty(1) to determine the number of columns. The use of the