mirror of
https://github.com/kvz/bash3boilerplate.git
synced 2025-05-05 09:52:49 +00:00
No longer try to use gsed in templater on OSX thanks to .bak workaround
This commit is contained in:
parent
0917b75cb9
commit
d43cecf24a
@ -30,10 +30,6 @@
|
|||||||
# Copyright (c) 2016 Kevin van Zonneveld (http://kvz.io)
|
# Copyright (c) 2016 Kevin van Zonneveld (http://kvz.io)
|
||||||
|
|
||||||
function templater() {
|
function templater() {
|
||||||
sed=""
|
|
||||||
[ -n "$(which sed)" ] && sed="$(which sed)"
|
|
||||||
[ -n "$(which gsed)" ] && sed="$(which gsed)"
|
|
||||||
|
|
||||||
ALLOW_REMAINDERS="${ALLOW_REMAINDERS:-0}"
|
ALLOW_REMAINDERS="${ALLOW_REMAINDERS:-0}"
|
||||||
|
|
||||||
templateSrc="${1:-}"
|
templateSrc="${1:-}"
|
||||||
@ -50,14 +46,14 @@ function templater() {
|
|||||||
|
|
||||||
cp -f "${templateSrc}" "${templateDst}"
|
cp -f "${templateSrc}" "${templateDst}"
|
||||||
for var in $(env |awk -F= '{print $1}' |egrep '^[A-Z0-9_]+$'); do
|
for var in $(env |awk -F= '{print $1}' |egrep '^[A-Z0-9_]+$'); do
|
||||||
${sed} -i.bak -e "s#\${${var}}#${!var}#g" "${templateDst}"
|
sed -i.bak -e "s#\${${var}}#${!var}#g" "${templateDst}"
|
||||||
# this .bak dance is done for BSD/GNU portability: http://stackoverflow.com/a/22084103/151666
|
# this .bak dance is done for BSD/GNU portability: http://stackoverflow.com/a/22084103/151666
|
||||||
rm -f "${templateDst}.bak"
|
rm -f "${templateDst}.bak"
|
||||||
done
|
done
|
||||||
|
|
||||||
# cat "${templateDst}"
|
# cat "${templateDst}"
|
||||||
|
|
||||||
if grep '${' ${templateDst} && [ "${ALLOW_REMAINDERS}" = "0" ]; then
|
if grep '${' "${templateDst}" && [ "${ALLOW_REMAINDERS}" = "0" ]; then
|
||||||
echo "ERROR: Unable to replace the above template vars"
|
echo "ERROR: Unable to replace the above template vars"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user