]> Git in Space - ssg/blobdiff - ssg
Allow searching up for prefix files
[ssg] / ssg
diff --git a/ssg b/ssg
index 36b2cb82fab789abf826a6810b910147856270c1..e8c2d9d4f80ed9b14292fcd3816610aea407fa03 100755 (executable)
--- a/ssg
+++ b/ssg
@@ -97,9 +97,20 @@ function evaluate() {
        done
 }
 
+function get-affix() {
+       name="$1"
+       shift
+       target="$1"
+       while :; do
+               [[ -f "$target/$name" ]] && break
+               target="$(dirname "$target")"
+       done
+       echo "$target/$name"
+}
+
 # evaluate
-pre="$(dirname "$file")/PREFIX"
-suf="$(dirname "$file")/SUFFIX"
+pre="$(get-affix PREFIX "$(dirname "$file")")"
+suf="$(get-affix SUFFIX "$(dirname "$file")")"
 if [[ -r "$pre" ]] ; then
        echo "Prefix file '$pre' available" > /dev/stderr
        evaluate < "$pre"