aboutsummaryrefslogtreecommitdiff
path: root/tools/find-upwards
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-01-09 23:17:37 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-01-09 23:17:37 +0100
commitf04bb93e982060ed27e5cf6e4a8d97edeb0910b6 (patch)
tree5dc44812f253699dc3b05be7895169ece61e6453 /tools/find-upwards
parent0a1fdd0eb9642e52f985971827beb33d54f21cf4 (diff)
downloadvis-lspc-f04bb93e982060ed27e5cf6e4a8d97edeb0910b6.tar.gz
vis-lspc-f04bb93e982060ed27e5cf6e4a8d97edeb0910b6.zip
extract the upwards find code into the util module
Diffstat (limited to 'tools/find-upwards')
-rwxr-xr-xtools/find-upwards26
1 files changed, 26 insertions, 0 deletions
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"