public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Sam James" <sam@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoo-functions:master commit in: functions/
Date: Sun,  7 Jul 2024 05:55:38 +0000 (UTC)	[thread overview]
Message-ID: <1719596367.9dc4a6c4a383b1214babe14b4b7091ad56840486.sam@gentoo> (raw)

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
+}


             reply	other threads:[~2024-07-07  5:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-07  5:55 Sam James [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-08-05  2:02 [gentoo-commits] proj/gentoo-functions:master commit in: functions/ Sam James
2024-08-02 23:14 Sam James
2024-07-07  5:55 Sam James
2024-07-07  5:55 Sam James
2024-06-25  4:06 Sam James

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1719596367.9dc4a6c4a383b1214babe14b4b7091ad56840486.sam@gentoo \
    --to=sam@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox