From 6de519643b5fcbf188a3172e57d123917e8648b5 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sat, 3 Aug 2024 18:08:48 +0200 Subject: style(instantiate_templates): Use a function invocation --- instantiate_templates.sh | 50 +++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 22 deletions(-) (limited to 'instantiate_templates.sh') 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 -- cgit 1.4.1