Check sed version instead of OS, dedupe sed script

This commit is contained in:
Midgard 2020-09-08 14:51:39 +02:00
parent 769f4ddd5d
commit a5fa7e4205
Signed by: midgard
GPG key ID: 511C112F1331BBB4

View file

@ -45,21 +45,17 @@ cp -r template_module "$module_dir"
cd "$module_dir"
# Fill in the blanks in the template
if [ "$(uname)" == "Darwin" ]; then
sed -i '' -e "
s/{YEAR}/$(date +%Y)/
s%{AUTHOR}%$author%
s%{MODULE_NAME}%$module_name%
s%{MODULE}%$module%
" $(find . -type f)
else
sed -i "
s/{YEAR}/$(date +%Y)/
s%{AUTHOR}%$author%
s%{MODULE_NAME}%$module_name%
s%{MODULE}%$module%
" $(find -type f)
fi
sed_script="
s/{YEAR}/$(date +%Y)/
s%{AUTHOR}%$author%
s%{MODULE_NAME}%$module_name%
s%{MODULE}%$module%"
case "$(sed --help 2>&1)" in
# GNU sed wants `-i` and BSD sed wants `-i ''`
*GNU*) sed -i -e "$sed_script" $(find . -type f); ;;
*) sed -i '' -e "$sed_script" $(find . -type f); ;;
esac
# Arduino IDE requires .ino sketches to have the same name as their directory
mv main.ino "$module.ino"