about summary refs log tree commit diff stats
path: root/instantiate_templates.sh
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-03 18:08:48 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-03 18:08:48 +0200
commit6de519643b5fcbf188a3172e57d123917e8648b5 (patch)
tree6b92c8ec0125531d80c6ab873a76bb9c32715a53 /instantiate_templates.sh
parentchore(build): Regenerate (diff)
downloadflake-templates-6de519643b5fcbf188a3172e57d123917e8648b5.tar.gz
flake-templates-6de519643b5fcbf188a3172e57d123917e8648b5.zip
style(instantiate_templates): Use a function invocation
Diffstat (limited to 'instantiate_templates.sh')
-rwxr-xr-xinstantiate_templates.sh50
1 files changed, 28 insertions, 22 deletions
diff --git a/instantiate_templates.sh b/instantiate_templates.sh
index 8b7b3e8..c991267 100755
--- a/instantiate_templates.sh
+++ b/instantiate_templates.sh
@@ -18,28 +18,34 @@ DRY_RUN_CMD=""
 [ -n "$ROOT" ] && $DRY_RUN_CMD rm --recursive "$ROOT/build"
 $DRY_RUN_CMD mkdir --parents "$ROOT/build"
 
-fd . "$ROOT/templates" --max-depth 1 --type directory | while read -r template; do
-    echo "Instantiating template: '.${template#"$ROOT"}'.."
-    template_new_path="$ROOT/build/$(basename "$template")"
-    $DRY_RUN_CMD cp --no-target-directory --recursive "${template%/}" "$template_new_path"
-
-    {
-        # Show directories
-        fd . "$template_new_path" --type symlink --follow --hidden
-
-        # Show simple files
-        fd . "$template_new_path" --type symlink --hidden
-    } | while read -r symlink; do
-        symlink_path="$(readlink --canonicalize "$symlink")"
-
-        if stringContain "$ROOT" "$symlink_path"; then
-            echo "     -> Instantiating symlink: '.${symlink#"$ROOT"}'.."
-            $DRY_RUN_CMD rm "$symlink"
-            $DRY_RUN_CMD cp "$symlink_path" "$symlink"
-        else
-            echo "     -> Not instantiating symlink '.${symlink#"$ROOT"}', as it points outside the repo!"
-        fi
+instantiate_dir() {
+    dir="$1"
+
+    fd . "$dir" --max-depth 1 --type directory | while read -r template; do
+        echo "Instantiating template: '.${template#"$ROOT"}'.."
+        template_new_path="$ROOT/build/$(basename "$template")"
+        $DRY_RUN_CMD cp --no-target-directory --recursive "${template%/}" "$template_new_path"
+
+        {
+            # Show directories
+            fd . "$template_new_path" --type symlink --follow --hidden
+
+            # Show simple files
+            fd . "$template_new_path" --type symlink --hidden
+        } | while read -r symlink; do
+            symlink_path="$(readlink --canonicalize "$symlink")"
+
+            if stringContain "$ROOT" "$symlink_path"; then
+                echo "     -> Instantiating symlink: '.${symlink#"$ROOT"}'.."
+                $DRY_RUN_CMD rm "$symlink"
+                $DRY_RUN_CMD cp --recursive "$symlink_path" "$symlink"
+            else
+                echo "     -> Not instantiating symlink '.${symlink#"$ROOT"}', as it points outside the repo!"
+            fi
+        done
     done
-done
+}
+
+instantiate_dir "$ROOT/templates"
 
 # vim: ft=sh