DEV Community

Discussion on: ShowDEV: Bash-TPL - A smart, lightweight shell script templating engine

Collapse
tekwizely profile image
TekWizely Author • Edited on

Greetings!

a more comprehensive scripting language

Bash-TPL allows you to use the FULL power of the shell scripting language of your choice, so I think we're saying the same thing.

What problem does this solve?

As with any templating language, the problem being solved is enabling you to mix some kind of logic in with a well-formatted textual file (say an HTML file, XML file, apache config, ad-hoc blog template, etc)

Say you have ~100 line config template (maybe an apache vhost template or somesuch), do you really want to be writing 100+ printf lines ?

bash-tpl manages converting your well-formatted and easy to edit text file into printf lines, while allowing you easily inject scripting logic around the file ...

The smart indentation tracking allows you clearly integrate your shell scripting without affecting the final resulting whitespace.

Trivial example:

Say you want:

<ul>
    <li>item1</li>
    <li>item2</li>
</ul>
Enter fullscreen mode Exit fullscreen mode

Given a template:

<ul>
    % for i in "${items}"; do
        %# The indentation introduced by for loop content
        %# will NOT be present in the output
        <li><% $i %></li>
    % done
</ul>
Enter fullscreen mode Exit fullscreen mode

This will generate the expected output, even though you added whitespace in order to make the for-loop content clearly visible and easier to edit.

I hope that helps a bit - thanks for looking and I'm happy to answer any other questions you might have.

-TW
edit: grammar,typos

Collapse
moopet profile image
Ben Sinclair

Gotcha, the example of generating a configuration file makes perfect sense.