@@ -14,6 +14,16 @@ usage() {
1414 echo " <new-formula-name> should not be any of 'bin' 'docs' 'test'." 1>&2
1515}
1616
17+ sedi () {
18+ # Run different sed -i arguments based on GNU vs BSD sed
19+ # See https://stackoverflow.com/a/38595160
20+ if sed --version > /dev/null 2>&1 ; then
21+ sed -i" " " $@ "
22+ else
23+ sed -i " " " $@ "
24+ fi
25+ }
26+
1727args () {
1828 if [ $# -ne 1 ]; then
1929 usage
@@ -36,19 +46,22 @@ convert_formula() {
3646 # See https://stackoverflow.com/a/15572071/5009408
3747 git reset \
3848 " $( echo ' feat: initial commit' \
39- | git commit-tree ' HEAD^{tree}' ) "
49+ | git commit-tree ' HEAD^{tree}' ) "
4050 git rm --quiet bin/convert-formula.sh AUTHORS.md CHANGELOG.md \
4151 docs/_static/css/custom.css docs/AUTHORS.rst docs/CHANGELOG.rst \
4252 docs/conf.py docs/CONTRIBUTING_DOCS.rst docs/index.rst
4353 git mv TEMPLATE " ${NEW_NAME} "
4454 grep --recursive --files-with-matches --exclude-dir=.git TEMPLATE . \
45- | xargs -L 1 ex -u NONE -sc ' %s/TEMPLATE/' " ${NEW_NAME} " ' /g|x'
46- # Searching across multiple lines.
47- # See https://vim.fandom.com/wiki/Search_across_multiple_lines
48- ex -u NONE -sc ' %s/^.. <REMOVEME\_.\{-}.. REMOVEME>/None/g|x' docs/README.rst
49- ex -u NONE -sc ' %s/^\s*# <REMOVEME\_.\{-}# REMOVEME>\n//g|x' .travis.yml
50- ex -u NONE -sc ' %s/^\s*# <REMOVEME\_.\{-}# REMOVEME>\n//g|x' .rubocop.yml
51- ex -u NONE -sc ' %s/^\(version:\).*/\1 1.0.0/g|x' FORMULA
55+ | while read -r filename; do
56+ sedi ' s/TEMPLATE/' " ${NEW_NAME} " ' /g' " ${filename} "
57+ done
58+ sedi ' s/^\(version:\).*/\1 1.0.0/' FORMULA
59+ # Deleting lines between two patterns
60+ sedi ' /<REMOVEME/,/REMOVEME>/d' .travis.yml .rubocop.yml
61+ # shellcheck disable=SC1004 # This backslash+linefeed is literal (sed: replace text)
62+ sedi ' /<REMOVEME/,/REMOVEME>/c \
63+ None
64+ ' docs/README.rst
5265 # shellcheck disable=SC2016 # Expressions don't expand in single quotes
5366 git commit --quiet --all \
5467 --message ' feat: convert `template-formula` to `' " ${NEW_NAME} " ' -formula`' \
0 commit comments