From f04bb93e982060ed27e5cf6e4a8d97edeb0910b6 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Thu, 9 Jan 2025 23:17:37 +0100 Subject: extract the upwards find code into the util module --- tools/find-upwards | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 tools/find-upwards (limited to 'tools/find-upwards') diff --git a/tools/find-upwards b/tools/find-upwards new file mode 100755 index 0000000..5f0edfe --- /dev/null +++ b/tools/find-upwards @@ -0,0 +1,26 @@ +#!/bin/sh + +set -eu + +if [ ! "${1:-}" ]; then + exit 1 +fi + +BASEDIR="$(dirname "$1")" + +while read -r glob; do + cd "$BASEDIR" + + while [ "$PWD" != "/" ]; do + set -- "$glob" + + if [ -e "$1" ]; then + echo "$PWD" + exit 0 + fi + + cd .. + done +done + +echo "$BASEDIR" -- cgit v1.2.3