4 ms·
I needed a simple templating tool recently and thought about m4, but found myself to be too busy to dive into it deeply enough. In the end, I just used a Bash s
by Xophmeister 5y ago
I needed a simple templating tool recently and thought about m4, but found myself to be too busy to dive into it deeply enough. In the end, I just used a Bash script with a heredoc, using jq/yq to read from JSON/YAML. A poor man's Jinja2:
#!/usr/bin/env bash
declare SOMETHING="$(yq eval ".yaml.query" whatever.yml)"
cat <<EOF
Here is my template. It says ${SOMETHING}.
EOF
It's not pretty, but it works! You can obviously shell out to anything in the heredoc, so it's quite flexible. Imports that respect the variables might be a bit tricky; maybe just have them as separate scripts like the above and use environment variables to to pass information around would be easiest.