aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xinstantiate_templates.sh44
1 files changed, 25 insertions, 19 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"
+instantiate_dir() {
+ dir="$1"
- {
- # Show directories
- fd . "$template_new_path" --type symlink --follow --hidden
+ 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 simple files
- fd . "$template_new_path" --type symlink --hidden
- } | while read -r symlink; do
- symlink_path="$(readlink --canonicalize "$symlink")"
+ {
+ # Show directories
+ fd . "$template_new_path" --type symlink --follow --hidden
- 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
+ # 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