From c80bbcfb018e0d2fc8cee4f23ab85d650fec6709 Mon Sep 17 00:00:00 2001 From: xyny <60004820+xynydev@users.noreply.github.com> Date: Thu, 19 Sep 2024 16:15:33 +0300 Subject: [PATCH] fix(script): only cd into scripts directory if scripts are defined (#335) --- modules/script/script.sh | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/modules/script/script.sh b/modules/script/script.sh index b962bce..c962766 100644 --- a/modules/script/script.sh +++ b/modules/script/script.sh @@ -6,14 +6,18 @@ set -euo pipefail get_yaml_array SCRIPTS '.scripts[]' "$1" get_yaml_array SNIPPETS '.snippets[]' "$1" -cd "$CONFIG_DIRECTORY/scripts" -# Make every script executable -find "$PWD" -type f -exec chmod +x {} \; -for SCRIPT in "${SCRIPTS[@]}"; do - echo "Running script $SCRIPT" - "$PWD/$SCRIPT" -done +# shellcheck disable=SC2153 +if [[ ${#SCRIPTS[@]} -gt 0 ]]; then + cd "$CONFIG_DIRECTORY/scripts" + # Make every script executable + find "$PWD" -type f -exec chmod +x {} \; + for SCRIPT in "${SCRIPTS[@]}"; do + echo "Running script $SCRIPT" + "$PWD/$SCRIPT" + done +fi +# shellcheck disable=SC2153 for SNIPPET in "${SNIPPETS[@]}"; do echo "Running snippet $SNIPPET" bash -c "$SNIPPET"