From 6e6458516de99ec4a606f892cb8b4ec0ff598612 Mon Sep 17 00:00:00 2001 From: jeremy avnet Date: Fri, 18 May 2018 17:10:33 -0700 Subject: [PATCH 1/2] Fix ShellCheck warning 2219 https://github.com/koalaman/shellcheck/wiki/SC2219 --- terraform_docs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform_docs.sh b/terraform_docs.sh index fba5730fd..6b06257b2 100755 --- a/terraform_docs.sh +++ b/terraform_docs.sh @@ -15,7 +15,7 @@ for file_with_path in "$@"; do tfvars_files+=("$file_with_path") fi - let "index+=1" + ((index+=1)) done readonly tmp_file="tmp_$(date | md5).txt" From 84e6b7f56d197309ff6f9a0fba49c3d4b6d735bc Mon Sep 17 00:00:00 2001 From: jeremy avnet Date: Fri, 18 May 2018 18:37:56 -0700 Subject: [PATCH 2/2] Replace GNU sed commands with perl This replaces the sed commands which required GNU sed be installed with perl versions. This should make this script more universally usable (e.g., on macOS) without installing additional tools. --- terraform_docs.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/terraform_docs.sh b/terraform_docs.sh index 6b06257b2..964bbcdd0 100755 --- a/terraform_docs.sh +++ b/terraform_docs.sh @@ -33,11 +33,11 @@ for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do terraform-docs md ./ > "$tmp_file" - # Replace content between markers with the placeholder - http://fahdshariff.blogspot.no/2012/12/sed-mutli-line-replacement-between-two.html - sed -i -n '/BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK/{p;:a;N;/END OF PRE-COMMIT-TERRAFORM DOCS HOOK/!ba;s/.*\n/I_WANT_TO_BE_REPLACED\n/};p' "$text_file" + # Replace content between markers with the placeholder - https://stackoverflow.com/questions/1212799/how-do-i-extract-lines-between-two-line-delimiters-in-perl#1212834 + perl -i -ne 'if (/BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK/../END OF PRE-COMMIT-TERRAFORM DOCS HOOK/) { print $_ if /BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK/; print "I_WANT_TO_BE_REPLACED\n$_" if /END OF PRE-COMMIT-TERRAFORM DOCS HOOK/;} else { print $_ }' "$text_file" - # Replace placeholder with the content of the file - https://stackoverflow.com/a/31057013/550451 - sed -i -e "/I_WANT_TO_BE_REPLACED/r $tmp_file" -e "//d" "$text_file" + # Replace placeholder with the content of the file + perl -i -e 'open(F, "'"$tmp_file"'"); $f = join "", ; while(<>){if (/I_WANT_TO_BE_REPLACED/) {print $f} else {print $_};}' "$text_file" rm -f "$tmp_file"