Skip to content

Releases: TekWizely/bash-tpl

Exit Code 0 On Success - v0.7.1

03 May 23:09
8ce79db
Compare
Choose a tag to compare

Small bugfix to ensure that script exits with code 0 on success.

I think I fell victim to forgetting that BATS run helper always succeeds and requires caller to explicitly check the result in $status.

This check has now been added as part of the tpl.bats.bats tests.

Core Logic Re-Write; A Few Breaking Changes - v0.7.0

11 Nov 16:25
331f87d
Compare
Choose a tag to compare

Bash-TPL

A Smart, Lightweight shell script templating engine, written in Bash.

Release - v0.7.0

This is mostly an internal update, working to simplify the indentation-tracking logic, while also making it more accurate.

The result is code that is easier to understand and also hopefully easier to enhance in the future.

It does also have the benefit of reducing the total script size by about 60 lines.

Full Changelog: v0.6.0...v0.7.0

Breaking Changes

Although targeted as an internal update, it does introduce several breaking changes:

Printf Indentation

Given the following input file:

test.tpl

one
	two
		three
	four
five

The previous versions would generate the following script:

printf "%s\n" one
	printf "%s\n" $'\ttwo'
		printf "%s\n" $'\t\tthree'
	printf "%s\n" $'\tfour'
printf "%s\n" five

Having the indentation of the printf match the indentation of the text seemed like a useful feature that would provide added context to the user when reviewing/debugging the script.

User feedback suggested that the opposite was true; That the added indentation made reviewing the script more difficult.

So this version makes the indentation of the printf statements more predictable.

printf "%s\n" one
printf "%s\n" $'\ttwo'
printf "%s\n" $'\t\tthree'
printf "%s\n" $'\tfour'
printf "%s\n" five

Missing Stmt-Block Close

In this new version, and un-closed stmt-block will generate an error:

test.tpl

%
    echo "Hello, world"

compile

$ bash-tpl test.tpl

Error: Missing stmt-block close ('%')

Un-Balanced Stmt-Block Close

In this new version, an error is generated if the stmt-block close does not have the same indentation as the stmt-block open:

test.tpl

    %
        echo "Hello, world"
  %

compile

$ bash-tpl test.tpl

Error: stmt-block close indentation does not match open

Un-Indented Stmt-Block Content

Regarding the following template, which contains stmt-block lines which are not indented beyond the stmt-block start:

test.tpl

  %
   #1
  #2
 #3
#4
  %

Since bash-tpl encourages you to utilize indentation, not-doing so results in "undefined" behavior.

Thats still true in spirit, but this release tries to make the resulting output a bit more predictable.

That is, it tries to make the output match the input, by ignoring the stmt-block indentation and disabling indentation-correction:

output

   #1
  #2
 #3
#4

Empty-Line In == Empty Line Out

This is actually more of a bug fix.

Previously, some scenarios could result in leading whitespace on a line that was indented to be empty.

This version tries harder to ensure that an empty line in your input templates yields an appropriately empty line in the output.

Feature: Text Lines Within Statement Blocks - v0.6.0

25 Sep 20:31
94e19e1
Compare
Choose a tag to compare

Bash-TPL

A Smart, Lightweight shell script templating engine, written in Bash.

Release - v0.6.0

feat: Text lines within Statement Blocks

This release introduces the ability to easily insert text lines within statement block bodies, without having close/re-open the blocks.

previously.tpl

%
    # ...
    if (condition); then
%
condition text ...
%
    else
%
else text ...
%
    fi
    # ...
%

now.tpl

%
    # ...
    if (condition); then
        % condition text ...
    else
        % else text ...
    fi
    # ...
%

NOTES:

  • The indentation of the printed text lines will always match that of the statement block start tag
  • This is to encourage you to format your text lines within the context of your script
  • All whitespce after the text line tag ('% ') will be printed as-as
Better-Formatted Scripts

In addition to being less-verbose, the generated scrips are also formatted better:

previously.sh

# ...
if (condition); then
printf "%s\n" condition\ text\ ...
else
printf "%s\n" else\ text\ ...
fi
# ...

now.sh

# ...
if (condition); then
    printf "%s\n" condition\ text\ ...
else
    printf "%s\n" else\ text\ ...
fi
# ...

bug: Indentation not tacked if first line of statement block not indented

There's been a long-standing bug where indentation tracking within statement blocks is not accurate if the first line of the block is not indented.

Essentially, bash-tpl was using the first line as the basis indentation tracking for the block, which broke down if that first line was not actually indented.

Now, the code keep searching for the first indented line, and uses that line as the basis.

This should provide more consistent behavior to otherwise well-indented scripts in the case where the first line of the block happens to not be indented.

Breaking Change

Due to the possible changes in leading whitespace in template output, this is considered a breaking change.

Full ChangeLog

Full Changelog: v0.5.0...v0.6.0

Fixed: Else Indentation; Dropping Unindented Directives - v0.5.0

11 Dec 00:58
4ba5afd
Compare
Choose a tag to compare

Bash-TPL

A Smart, Lightweight shell script templating engine, written in Bash.

Release - v0.5.0

chore: GitHub workflow to run tests against various Bash versions

Added a github worfkflow to execute the bats tests against multiple versions of Bash

I even wrote a blog post about it.

chore: Apply newly reported shellcheck recommendations

I updated shellcheck at some point after my last release and it started reporting a new error:

  • SC2184 - Quote arguments to unset so they're not glob expanded.

Although this SC has been around for a long time, I'm certain that seeing it in my shellcheck report is new.

fix: Track indentation after all statement lines, not just between logical "open"/"close"

I was writing a template with an if/else/fi block and realized that bash-tpl wasn't correctly tracking indentation on the else section.

% # one
	1: This text should be indent-tracked
% # two
	2: This text should be indent-tracked
% # three
	3: This text should be indent-tracked

Previously, section 2 was not being correctly tracked.

I was treating the first encountered statement line as an maybe-open and any subsequent line as a cose, when in fact they should always be seen as a maybe-open and a maybe-close

Breaking Change

Due to the possible changes in leading whitespace in template output, this is considered a breaking change.

fix: Stop ignoring unindented directives in text blocks

There was a real bug that was dropping directive statements when were part of a text block, but did not exist at the same (or deeper) indentation of the text block.

I only discovered this by accident while writing a test for the indentation fix above.

Full ChangeLog

Full Changelog: v0.4.0...v0.5.0

Support for Older Bash Versions (3.2, 4.4, etc) - v0.4.0

11 Nov 23:25
437cc96
Compare
Choose a tag to compare

Bash-TPL

A Smart, Lightweight shell script templating engine, written in Bash.

Release - v0.4.0

  • Adds support for Bash versions 3.2+

Thanks to @flaix for pointing out that I inadvertently broke support for older bash versions by using constructs that were only available in newer versions.

I re-worked the code the also ran the existing BATS tests against multiple Bash versions: 3.2, 4.4, 5.0, and 5.1

Commit Log (since previous release)

ef3b2ab feat: Re-worked to support Bash v3.2 and v4.4 (#7)
232a28d docs: Firm up README
6261feb docs: Feature callouts, Similar Tools

Full Changelog: v0.3.0...v0.4.0

STDIN, Pipes, and Heredocs; Template tests - v0.3.0

23 Jul 21:30
9ba19a8
Compare
Choose a tag to compare

Bash-TPL

A Smart, Lightweight shell script templating engine, written in Bash.

Release - v0.3.0

  • Adds support for reading from stdin, including pipes, herestrings and heredocs.

  • Updates tests with ability to render a template file and compare it to a shell script file.

Commit Log (since previous release)

fa57897 Docs for stdin, usage to top of file
37dc9da main, -, --, |, tpl tests !
867616a Fixes s/script/statement/ in TOC; Bumps version to v0.3.0-SNAPSHOT

Regexes and Readmes - v0.2.0

09 Jul 20:25
8d9f369
Compare
Choose a tag to compare

Bash-TPL

A Smart, Lightweight shell script templating engine, written in Bash.

Release - v0.2.0

Adds tests to better-validate the regexes and tag parsers - Fixes discovered bugs accordingly :)

Greatly fleshes out the README

Adding bash-tpl into your project

The bash-tpl script has an embedded MIT SPDX header, as well as a license header, and should be safe for you to extract and add to your own projects for easy template generation.

Commit Log (since previous release)

2ddfd67 - Fix tag regexes; s/script/statement/ tag|line
71bbbf5 - Fleshes out README
37f792b - Fleshes out README
7271534 - Flesh out Text Tag docs a bit; typos (delimIter)
9c17288 - Reduces subshells using globals or var refs
c7177b8 - Adds --reset-delims; Lets .INCLUDE pass args

First Release - v0.1.0

04 Jul 00:17
609e833
Compare
Choose a tag to compare

Bash-TPL

A Smart, Lightweight shell script templating engine, written in Bash.

First Release - v0.1.0

I believe Bash-TPL is ready for its first release!

  • Casual usage shows it to be working as intended
  • Some BATS tests have been written and all tests pass
  • Usage (bash-tpl --help) command has been added
  • Version (bash-tpl --version) command has been added
  • Minimally useful README
  • Need to create a release in order to create a brew tap :)