diff options
Diffstat (limited to 'instantiate_templates.sh')
-rwxr-xr-x | instantiate_templates.sh | 50 |
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 |