diff --git a/README.md b/README.md index 89b5e82..43ace65 100644 --- a/README.md +++ b/README.md @@ -8,13 +8,15 @@ Sébastien Lavoie Johan Haleby +Stefan Rinke + See http://code.haleby.se/2015/11/20/simple-templating-engine-in-bash/ and http://blog.lavoie.sl/2012/11/simple-templating-system-using-bash.html for more details ## Installation To install templater in linux type: - sudo curl -L https://raw.githubusercontent.com/johanhaleby/bash-templater/master/templater.sh -o /usr/local/bin/templater + sudo curl -L https://raw.githubusercontent.com/sker65/bash-templater/master/templater.sh -o /usr/local/bin/templater sudo chmod +x /usr/local/bin/templater ## Usage @@ -38,6 +40,14 @@ AUTHOR=Johan VERSION=1.2.3 ``` +Added an option -r to replace all variables in the templace *in place* and save the original template as .bak. + +example: +```bash +AUTHOR=Stefan templater template -r +``` + + Don't print any warning messages: ```bash diff --git a/templater.sh b/templater.sh index e96f2ff..7bf609e 100755 --- a/templater.sh +++ b/templater.sh @@ -44,6 +44,8 @@ where: Don't do anything, just print the result of the variable expansion(s) -f, --file Specify a file to read variables from + -r, --replace + Replace template file with rendered version -s, --silent Don't print warning messages (for example if no variables are found) @@ -76,6 +78,9 @@ if [ "$#" -ne 0 ]; then -p|--print) print_only="true" ;; + -r|--replace) + replace="true" + ;; -f|--file) config_file="$2" ;; @@ -165,5 +170,9 @@ for var in $vars; do replaces="-e 's/{{$var}}/${value}/g' $replaces" done +if [[ "$replace" == "true" ]]; then + SED_OPT="-i .bak" +fi + escaped_template_path=$(echo $template | sed 's/ /\\ /g') -eval sed $replaces "$escaped_template_path" +eval sed $SED_OPT $replaces "$escaped_template_path" \ No newline at end of file