- Description:
- Simple templating script
- Last Change:
- Clone URL:
ssh://anonymous@git.linskey.org/tpl
- ECDSA:
SHA256:NGp9Hbafw+cmfseVXcP9q9zBAU0tLvvzRYQEsJdAJDg
- ED25519:
SHA256:Wr25Bc8kREsGVjh7OY+yNRx6hUDD68qr2eKsvPc0y6w
- RSA:
SHA256:egEdHfpk8FWAExkycQm+RmqcfrTovy/joYsa2GDGDt4
Commit Briefs
Improve readme (main)
Update readme
Fixed program name in main header, improved and expanded some text, fixed some inacurate specification details, fixed a typo, and improved formatting.
Bump version to 1.0.1 (tags/v1.0.1)
Improve variable substitution efficiency
If a value in the variables file contains multiple instances of the same variable, they will all be replaced in a single function call, eliminating the need to loop over the same block of code multiple times.
Fix brace escaping in regexes
The POSIX extended regular expression spec requires that the left brace character be escaped when it appears outside of an interval expression. The results are undefined if the brace is not escaped.[^1] The ERE spec permits right braces to be escaped, though this isn't required.[^2] But the standard ERE escaping rules are superseded in the POSIX awk specification. The awk spec does not specify a right brace escape sequence, so the meaning of an escaped right brace is undefined.[^3] We have a number of escaped right braces and one instance of a string variable containing unescaped left braces being passed to a function as a regex. These don't cause any problems in practice, but to ensure maximum portability and pedantry, we bring everything into strict compliance with the spec here. [^1]: POSIX.1-2024 XBD 9.4.3: <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap09.html#tag_09_04_03> [^2]: POSIX.1-2024 XBD 9.4.2: <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap09.html#tag_09_04_02> [^3]: POSIX.1-2024 awk: <https://pubs.opengroup.org/onlinepubs/9799919799/utilities/awk.html#tag_20_06_13_04>
Branches
Tree
| LICENSE | commits | blame |
| README.md | commits | blame |
| example/ | |
| test.sh* | commits | blame |
| tpl* | commits | blame |
README.md
# tpl
`tpl` is an extremely simple general-purpose templating tool written in
POSIX.1-2024-compliant AWK.
Usage:
tpl [vars file] [template file ...]
First define a list of variables in a file:
# This is a comment.
food = pizza
beverage = coffee
# Previously defined variables can be used in variable definitions.
# Whitespace is optional inside braces.
dinner = {{ food }} and {{beverage}}
# The = character can be surrounded by any number of whitespace
# characters.
one = 1
two = 2
three=3
Then reference those variables in your template files by enclosing them in
double braces:
My favorite food is {{ food }}, and my favorite beverage is
{{ beverage }}. I'm going to have {{ dinner }} for dinner tonight.
The first positive integers are {{one}}, {{two}}, and {{three}}.
{{one}} is the smallest of the three.
Then pass your variable file and template files, in that order, as arguments to
the `template` script. To see the examples above in action, run the following
command:
./tpl example/vars example/text.tpl
The result will be written to `stdout`.
You can also read from `stdin` by passing `-` in the file list:
echo "foo {{ bar }}" | ./tpl vars -
