Executing Templates
With the sketch exec command, you can render a template and then execute it as a shell command.
To do this, you can use a regular file, a template with an id (either defined in the config file or inside the templates_dir), or even one defined within the command itself.
Examples
From Template
Let's say that we have a file named cmd_template.j2 inside our templates_dir, and it looks like this:
echo "{{ category }} engine... {{ category }}... argh!" > output_from_templates_dir.txt
ℹ️ You do not have to use
.j2as an extension for the template files. Any extension can be used.
We can refer to it by its id:
sketch --set category="gp2" commands_tests -t cmd_template.j2
This will trigger the command and create a file containing
gp2 engine... gp2... argh!
From File
We can also use a file that is not inside templates_dir by using the -f flag and providing the path to said file. Relative paths will be resolved starting from the cwd.
So let's say that we have this template file:
echo "all the time you have to leave the {{ something }}!" > output_from_file.txt
Command:
sketch --set something="space" commands_tests -f cmd_from_file.j2
Output:
all the time you have to leave the space!
From Literal Template
Templates can also be defined directly as part of the command.
Command:
sketch --set condition="slower" commands_tests 'echo "engine feels good... much {{ condition }} than before... amazing" > command_output.txt'
Output:
engine feels good... much slower than before... amazing