* [gentoo-commits] proj/gentoo-functions:master commit in: functions/
@ 2024-06-25 4:06 Sam James
0 siblings, 0 replies; 6+ messages in thread
From: Sam James @ 2024-06-25 4:06 UTC (permalink / raw
To: gentoo-commits
commit: 94446b64cc9f9a912184a85fa43070fecbc4ce0f
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Wed Jun 12 12:51:55 2024 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Jun 23 21:19:15 2024 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=94446b64
Deprecate RC_NOCOLOR and the equivalent use of the positional parameters
Firstly, the "." builtin is not specified to support the passing of
arguments; such is a bashism. It is rather presumptuous to act as if the
present contents of the positional parameters are for the benefit of
gentoo-functions at the time of its initialisation.
Secondly, there exists a de-facto standard for suppressing colored
output, which is to define NO_COLOR as a non-empty string, per
https://no-color.org.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
functions/rc.sh | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/functions/rc.sh b/functions/rc.sh
index 519d847..2f2dc52 100644
--- a/functions/rc.sh
+++ b/functions/rc.sh
@@ -422,13 +422,16 @@ _is_visible()
#------------------------------------------------------------------------------#
# Determine whether the use of color is to be wilfully avoided.
-if [ -n "${NO_COLOR}" ]; then
+if [ "${RC_NOCOLOR+set}" ]; then
+ warn "the RC_NOCOLOR variable is deprecated by gentoo-functions; please set NO_COLOR instead"
+elif [ -n "${NO_COLOR}" ]; then
# See https://no-color.org/.
RC_NOCOLOR=yes
else
for _; do
case $_ in
--nocolor|--nocolour|-C)
+ warn "the $_ option is deprecated by gentoo-functions; please set NO_COLOR=1 instead"
RC_NOCOLOR=yes
break
esac
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [gentoo-commits] proj/gentoo-functions:master commit in: functions/
@ 2024-07-07 5:55 Sam James
0 siblings, 0 replies; 6+ messages in thread
From: Sam James @ 2024-07-07 5:55 UTC (permalink / raw
To: gentoo-commits
commit: b720081b68dfba3ed4ebacb4d7564977708bfa25
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Thu Jun 27 20:42:23 2024 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Jun 28 17:39:33 2024 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=b720081b
Add the int_between() and str_between() functions to experimental
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
functions/experimental.sh | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/functions/experimental.sh b/functions/experimental.sh
index e02923a..1aac078 100644
--- a/functions/experimental.sh
+++ b/functions/experimental.sh
@@ -12,6 +12,24 @@
warn "sourcing the experimental module from gentoo-functions; no stability guarantee is provided"
+#
+# Expects three parameters, all of which must be integers, and determines
+# whether the first is numerically greater than or equal to the second, and
+# numerically lower than or equal to the third.
+#
+int_between()
+{
+ if [ "$#" -lt 3 ]; then
+ warn "int_between: too few arguments (got $#, expected 3)"
+ false
+ elif ! is_int "$2" || ! is_int "$3"; then
+ _warn_for_args int_between "$@"
+ false
+ else
+ is_int "$1" && [ "$1" -ge "$2" ] && [ "$1" -le "$3" ]
+ fi
+}
+
#
# Returns 0 provided that two conditions hold. Firstly, that the standard input
# is connected to a tty. Secondly, that the standard output has not been closed.
@@ -52,6 +70,30 @@ prepend_ts()
prepend_ts
}
+#
+# Expects three parameters and determines whether the first is lexicographically
+# greater than or equal to the second, and lexicographically lower than or equal
+# to the third. The effective system collation shall affect the results, given
+# the involvement of the sort(1) utility.
+#
+str_between()
+{
+ local i
+
+ if [ "$#" -ne 3 ]; then
+ warn "str_between: wrong number of arguments (got $#, expected 3)"
+ false
+ else
+ set -- "$2" "$1" "$3"
+ i=0
+ printf '%s\n' "$@" |
+ sort |
+ while IFS= read -r line; do
+ eval "[ \"\${line}\" = \"\$$(( i += 1 ))\" ]" || ! break
+ done
+ fi
+}
+
#
# Takes the first parameter as either a relative pathname or an integer
# referring to a number of iterations. To be recognised as a pathname, the first
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [gentoo-commits] proj/gentoo-functions:master commit in: functions/
@ 2024-07-07 5:55 Sam James
0 siblings, 0 replies; 6+ messages in thread
From: Sam James @ 2024-07-07 5:55 UTC (permalink / raw
To: gentoo-commits
commit: 9dc4a6c4a383b1214babe14b4b7091ad56840486
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Thu Jun 27 20:36:10 2024 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Jun 28 17:39:27 2024 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=9dc4a6c4
Add the up() function to experimental
As based on the implementation in Maarten Billemont's bashlib library.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
functions/experimental.sh | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/functions/experimental.sh b/functions/experimental.sh
index f577fa7..e02923a 100644
--- a/functions/experimental.sh
+++ b/functions/experimental.sh
@@ -51,3 +51,31 @@ prepend_ts()
prepend_ts
}
+
+#
+# Takes the first parameter as either a relative pathname or an integer
+# referring to a number of iterations. To be recognised as a pathname, the first
+# four characters must form the special prefix, ".../". It recurses upwards from
+# the current directory until either the relative pathname is found to exist,
+# the specified number of iterations has occurred, or the root directory is
+# encountered. In the event that the root directory is reached without either of
+# the first two conditions being satisfied, the return value shall be 1.
+# Otherwise, the value of PWD shall be printed to the standard output.
+#
+up()
+{
+ local i
+
+ i=0
+ while [ "${PWD}" != / ]; do
+ chdir ../
+ case $1 in
+ .../*)
+ test -e "${1#.../}"
+ ;;
+ *)
+ test "$(( i += 1 ))" -eq "$1"
+ esac \
+ && pwd && return
+ done
+}
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [gentoo-commits] proj/gentoo-functions:master commit in: functions/
@ 2024-07-07 5:55 Sam James
0 siblings, 0 replies; 6+ messages in thread
From: Sam James @ 2024-07-07 5:55 UTC (permalink / raw
To: gentoo-commits
commit: fd79ab30122474ab5207ea001d92ffac677b5380
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Thu Jun 27 16:06:38 2024 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Jun 28 17:39:01 2024 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=fd79ab30
Add an experimental module for staging new ideas
The idea is to be able to write new functions without having to
initially commit to their being in the core library or, indeed, any of
the other modules. Experimental functions may be promoted or simply
dropped without warning if it is decided that they are insufficiently
useful to merit incorporation.
This initial commit defines the is_interactive() and prepend_ts()
functions.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
functions/experimental.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/functions/experimental.sh b/functions/experimental.sh
new file mode 100644
index 0000000..f577fa7
--- /dev/null
+++ b/functions/experimental.sh
@@ -0,0 +1,53 @@
+# Copyright 2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+# shellcheck shell=sh disable=3043
+
+# This file contains functions considered experimental in nature. Any functions
+# defined here may eventually be promoted to the core library or to a distinct
+# module. They may also be dropped without warning, either because they were
+# not considered as being sufficiently within the scope of gentoo-functions as
+# a project or because they were deemed to be insufficiently useful. As such, it
+# serves as a staging ground for new ideas. Note that GENFUN_API_LEVEL must
+# never be incremented on account of any changes made to this module.
+
+warn "sourcing the experimental module from gentoo-functions; no stability guarantee is provided"
+
+#
+# Returns 0 provided that two conditions hold. Firstly, that the standard input
+# is connected to a tty. Secondly, that the standard output has not been closed.
+# This technique is loosely based on the IO::Interactive::Tiny module from CPAN.
+#
+is_interactive()
+{
+ test -t 0 && { true 3>&1; } 2>/dev/null
+}
+
+#
+# Continuously reads lines from the standard input, prepending each with a
+# timestamp before printing to the standard output. Timestamps shall be in the
+# format of "%FT%T%z", per strftime(3). Output buffering shall not be employed.
+#
+prepend_ts()
+{
+ if hash gawk 2>/dev/null; then
+ prepend_ts()
+ {
+ gawk '{ print strftime("%FT%T%z"), $0; fflush(); }'
+ }
+ elif hash ts 2>/dev/null; then
+ prepend_ts()
+ {
+ ts '%FT%T%z'
+ }
+ elif bash -c '(( BASH_VERSINFO >= 4 ))' 2>/dev/null; then
+ prepend_ts()
+ {
+ bash -c 'while read -r; do printf "%(%FT%T%z)T %s\n" -1 "${REPLY}"; done'
+ }
+ else
+ warn "prepend_ts: this function requires that either bash, gawk or moreutils be installed"
+ return 1
+ fi
+
+ prepend_ts
+}
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [gentoo-commits] proj/gentoo-functions:master commit in: functions/
@ 2024-08-02 23:14 Sam James
0 siblings, 0 replies; 6+ messages in thread
From: Sam James @ 2024-08-02 23:14 UTC (permalink / raw
To: gentoo-commits
commit: d6e689bc832e4b033f4af9cb6746a99649ecc8d8
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Wed Jul 31 23:20:10 2024 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Jul 31 23:36:10 2024 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=d6e689bc
Treat EINFO_LOG as false if equal to RC_SERVICE
Consider the value of EINFO_LOG to be false in the event that it is
equal to the value of RC_SERVICE. The reason for this is that, as of the
time of writing, openrc-run(8) defines and uses EINFO_LOG in a way that
is at odds with gentoo-functions. Ideally, the behaviour of OpenRC would
be modified so that it becomes possible to jettison this workaround.
Fixes: 0dd8364c03c6f8737150ee4f146ddeeec57efee9
Bug: https://bugs.gentoo.org/936613
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
functions/rc.sh | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/functions/rc.sh b/functions/rc.sh
index 9129b32..9b1fc5d 100644
--- a/functions/rc.sh
+++ b/functions/rc.sh
@@ -117,7 +117,11 @@ eoutdent()
#
# Invokes the logger(1) utility, provided that EINFO_LOG is true. The first
# parameter shall be taken as a priority level, the second as the message tag,
-# and the remaining parameters as the message to be logged.
+# and the remaining parameters as the message to be logged. As a special case,
+# the value of EINFO_LOG shall be treated as if were false in the event that it
+# is equal to the value of RC_SERVICE. The reason for this is that, as of the
+# time of writing, openrc-run(8) defines and uses EINFO_LOG in a way that is
+# at odds with gentoo-functions.
#
esyslog()
{
@@ -126,7 +130,7 @@ esyslog()
if [ "$#" -lt 2 ]; then
warn "esyslog: too few arguments (got $#, expected at least 2)"
return 1
- elif yesno "${EINFO_LOG}" && hash logger 2>/dev/null; then
+ elif [ "${EINFO_LOG}" != "${RC_SERVICE}" ] && yesno "${EINFO_LOG}"; then
pri=$1 tag=$2
shift 2
msg=$*
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [gentoo-commits] proj/gentoo-functions:master commit in: functions/
@ 2024-08-05 2:02 Sam James
0 siblings, 0 replies; 6+ messages in thread
From: Sam James @ 2024-08-05 2:02 UTC (permalink / raw
To: gentoo-commits
commit: fed96ec1da2fad4070a02803ceef4a322a87eb4f
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sun Aug 4 23:48:04 2024 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Aug 4 23:53:22 2024 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=fed96ec1
Do not yet deprecate RC_NOCOLOR
It would be sensible to conduct a survey to determine whether - and
where - it is being used beforehand.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
functions/rc.sh | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/functions/rc.sh b/functions/rc.sh
index 9b1fc5d..12444d1 100644
--- a/functions/rc.sh
+++ b/functions/rc.sh
@@ -426,9 +426,7 @@ _is_visible()
#------------------------------------------------------------------------------#
# Determine whether the use of color is to be wilfully avoided.
-if [ "${RC_NOCOLOR+set}" ]; then
- warn "the RC_NOCOLOR variable is deprecated by gentoo-functions; please set NO_COLOR instead"
-elif [ -n "${NO_COLOR}" ]; then
+if [ "${NO_COLOR}" ]; then
# See https://no-color.org/.
RC_NOCOLOR=yes
else
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-08-05 2:02 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-02 23:14 [gentoo-commits] proj/gentoo-functions:master commit in: functions/ Sam James
-- strict thread matches above, loose matches on Subject: below --
2024-08-05 2:02 Sam James
2024-07-07 5:55 Sam James
2024-07-07 5:55 Sam James
2024-07-07 5:55 Sam James
2024-06-25 4:06 Sam James
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox