diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-08-03 18:08:48 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-08-03 18:08:48 +0200 |
commit | 6de519643b5fcbf188a3172e57d123917e8648b5 (patch) | |
tree | 6b92c8ec0125531d80c6ab873a76bb9c32715a53 | |
parent | chore(build): Regenerate (diff) | |
download | flake-templates-6de519643b5fcbf188a3172e57d123917e8648b5.tar.gz flake-templates-6de519643b5fcbf188a3172e57d123917e8648b5.zip |
style(instantiate_templates): Use a function invocation
-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 |