Skip to content

Commit c986c5e

Browse files
authored
fix(terraform_docs): Fix non-GNU sed issues, introduced in v1.93.0, as previous fix doesn't work correctly (antonbabenko#708)
1 parent 5051743 commit c986c5e

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,9 @@ Unlike most other hooks, this hook triggers once if there are any changed files
585585
To migrate everything to `terraform-docs` insertion markers, run in repo root:
586586

587587
```bash
588-
grep -rl --null 'BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK' . | xargs -0 sed -i'' -e 's/BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK/BEGIN_TF_DOCS/'
589-
grep -rl --null 'END OF PRE-COMMIT-TERRAFORM DOCS HOOK' . | xargs -0 sed -i'' -e 's/END OF PRE-COMMIT-TERRAFORM DOCS HOOK/END_TF_DOCS/'
588+
sed --version &> /dev/null && SED_CMD=(sed -i) || SED_CMD=(sed -i '')
589+
grep -rl --null 'BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK' . | xargs -0 "${SED_CMD[@]}" -e 's/BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK/BEGIN_TF_DOCS/'
590+
grep -rl --null 'END OF PRE-COMMIT-TERRAFORM DOCS HOOK' . | xargs -0 "${SED_CMD[@]}" -e 's/END OF PRE-COMMIT-TERRAFORM DOCS HOOK/END_TF_DOCS/'
590591
```
591592

592593
```yaml

hooks/terraform_docs.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ function main {
4040
function replace_old_markers {
4141
local -r file=$1
4242

43-
sed -i'' -e "s/^${old_insertion_marker_begin}$/${insertion_marker_begin}/" "$file"
44-
sed -i'' -e "s/^${old_insertion_marker_end}$/${insertion_marker_end}/" "$file"
43+
# Determine the appropriate sed command based on the operating system (GNU sed or BSD sed)
44+
sed --version &> /dev/null && SED_CMD=(sed -i) || SED_CMD=(sed -i '')
45+
"${SED_CMD[@]}" -e "s/^${old_insertion_marker_begin}$/${insertion_marker_begin}/" "$file"
46+
"${SED_CMD[@]}" -e "s/^${old_insertion_marker_end}$/${insertion_marker_end}/" "$file"
4547
}
4648

4749
#######################################################################

0 commit comments

Comments
 (0)