You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Replace terraform_docs use of GNU sed with perl (antonbabenko#15)
* Fix ShellCheck warning 2219
https://github.com/koalaman/shellcheck/wiki/SC2219
* 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.
Copy file name to clipboardExpand all lines: terraform_docs.sh
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ for file_with_path in "$@"; do
15
15
tfvars_files+=("$file_with_path")
16
16
fi
17
17
18
-
let"index+=1"
18
+
((index+=1))
19
19
done
20
20
21
21
readonly tmp_file=$(mktemp)
@@ -33,11 +33,11 @@ for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do
33
33
34
34
terraform-docs md ./ >"$tmp_file"
35
35
36
-
# Replace content between markers with the placeholder - http://fahdshariff.blogspot.no/2012/12/sed-mutli-line-replacement-between-two.html
37
-
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"
36
+
# Replace content between markers with the placeholder - https://stackoverflow.com/questions/1212799/how-do-i-extract-lines-between-two-line-delimiters-in-perl#1212834
37
+
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"
38
38
39
-
# Replace placeholder with the content of the file - https://stackoverflow.com/a/31057013/550451
40
-
sed -i -e "/I_WANT_TO_BE_REPLACED/r $tmp_file" -e "//d""$text_file"
39
+
# Replace placeholder with the content of the file
0 commit comments