Commit Briefs

8ed731583d Benjamin Linskey

Improve readme (main)


b240709d3e Benjamin Linskey

Update readme

Fixed program name in main header, improved and expanded some text, fixed some inacurate specification details, fixed a typo, and improved formatting.


fc2504a18b Benjamin Linskey

Bump version to 1.0.1 (tags/v1.0.1)


ffd126df6d Benjamin Linskey

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.


c1fedee856 Benjamin Linskey

Remove a period from a comment header


b10392c52d Benjamin Linskey

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>


653365c236 Benjamin Linskey

Add version number


1cedfb65dc Benjamin Linskey

Add a note about regex metacharacter escaping


2aa8ed870c Benjamin Linskey

Rename command to "tpl"


17f146903e Benjamin Linskey

Add header comment to script


Branches

Tags

v1.0.1

Tree

LICENSEcommits | blame
README.mdcommits | 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 -