Skip to content

Commit 051e400

Browse files
committed
ci(generate-cookiecutter-template-from-example-project): portable sed command
1 parent 2e057a2 commit 051e400

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

generate-cookiecutter-template-from-example-project.sh

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,29 @@ fi
99
mkdir "example-tryout"
1010
rsync -a ./example/ ./example-tryout/
1111
cd ./example-tryout
12-
pwd
13-
ls -lrt
12+
1413
# sets the locale for all commands run in the current shell session to the "C" locale, which is the default POSIX locale. This makes programs like sed and find treat files as raw bytes, ignoring any character encoding issues. It helps avoid errors like illegal byte sequence when processing files with mixed or unknown encodings.
1514
export LC_ALL=C
1615

17-
find . -type f -exec sed -e s/Examples/{{cookiecutter.domain_plural_capitalized}}/g -i '' '{}' ';'
16+
# Detect OS and set sed inline flag
17+
if [[ "$(uname)" == "Darwin" ]]; then
18+
SED_INPLACE=(-i '')
19+
else
20+
SED_INPLACE=(-i)
21+
fi
22+
23+
find . -type f -exec sed "${SED_INPLACE[@]}" -e s/Examples/{{cookiecutter.domain_plural_capitalized}}/g '{}' ';'
1824
find . -depth -name '*Examples*' -print0|while IFS= read -rd '' f; do mv -i "$f" "$(echo "$f"|sed -E 's/(.*)Examples/\1{{cookiecutter.domain_plural_capitalized}}/')"; done
19-
find . -type f -exec sed -e s/examples/{{cookiecutter.domain_plural}}/g -i '' '{}' ';'
25+
find . -type f -exec sed "${SED_INPLACE[@]}" -e s/examples/{{cookiecutter.domain_plural}}/g '{}' ';'
2026
find . -depth -name '*examples*' -print0|while IFS= read -rd '' f; do mv -i "$f" "$(echo "$f"|sed -E 's/(.*)examples/\1{{cookiecutter.domain_plural}}/')"; done
21-
find . -type f -exec sed -e s/Example/{{cookiecutter.domain_capitalized}}/g -i '' '{}' ';'
27+
find . -type f -exec sed "${SED_INPLACE[@]}" -e s/Example/{{cookiecutter.domain_capitalized}}/g '{}' ';'
2228
find . -depth -name '*Example*' -print0|while IFS= read -rd '' f; do mv -i "$f" "$(echo "$f"|sed -E 's/(.*)Example/\1{{cookiecutter.domain_capitalized}}/')"; done
23-
find . -type f -exec sed -e s/example/{{cookiecutter.domain}}/g -i '' '{}' ';'
29+
find . -type f -exec sed "${SED_INPLACE[@]}" -e s/example/{{cookiecutter.domain}}/g '{}' ';'
2430
find . -depth -name '*example*' -print0|while IFS= read -rd '' f; do mv -i "$f" "$(echo "$f"|sed -E 's/(.*)example/\1{{cookiecutter.domain}}/')"; done
25-
find . -type f -exec sed -e s/packagename/{{cookiecutter.package_name}}/g -i '' '{}' ';'
31+
find . -type f -exec sed "${SED_INPLACE[@]}" -e s/packagename/{{cookiecutter.package_name}}/g '{}' ';'
2632
find . -depth -name '*packagename*' -print0|while IFS= read -rd '' f; do mv -i "$f" "$(echo "$f"|sed -E 's/(.*)packagename/\1{{cookiecutter.package_name}}/')"; done
27-
find . -type f -exec sed -e s/artifactName/{{cookiecutter.artifact_id}}/g -i '' '{}' ';'
28-
find . -type f -exec sed -e s/group-id/{{cookiecutter.group_id}}/g -i '' '{}' ';'
33+
find . -type f -exec sed "${SED_INPLACE[@]}" -e s/artifactName/{{cookiecutter.artifact_id}}/g '{}' ';'
34+
find . -type f -exec sed "${SED_INPLACE[@]}" -e s/group-id/{{cookiecutter.group_id}}/g '{}' ';'
2935
## For the following, we need to replace EXAMPLES and EXAMPLE with the domain name
30-
find . -type f -exec sed -e s/EXAMPLES/{{cookiecutter.domain_plural_uppercase}}/g -i '' '{}' ';'
31-
find . -type f -exec sed -e s/EXAMPLE/{{cookiecutter.domain_uppercase}}/g -i '' '{}' ';'
36+
find . -type f -exec sed "${SED_INPLACE[@]}" -e s/EXAMPLES/{{cookiecutter.domain_plural_uppercase}}/g '{}' ';'
37+
find . -type f -exec sed "${SED_INPLACE[@]}" -e s/EXAMPLE/{{cookiecutter.domain_uppercase}}/g '{}' ';'

0 commit comments

Comments
 (0)