A commandline, POSIX-compliant logic-less template engine similar to Mustache/Handlebars.
smallstache
takes template from commandline argument and key-value data from stdin:
$ echo 'Hello {{ something }}!' >template
$ echo 'something=World' | smallstache template
Hello World!
It can use any source of standard unix key-value data format:
$ echo 'Your PATH variable: {{ PATH }}' >template
$ set | smallstache template
Your PATH variable: /bin:/usr/bin
The instruction is for Linux. On different OSes, you may need to use different commands
-
Download latest stable release from GitHub:
wget https://github.com/macie/smallstache.sh/releases/latest/download/smallstache
-
(OPTIONAL) Verify downloading:
wget https://github.com/macie/smallstache.sh/releases/latest/download/smallstache.sha256sum sha256sum -c smallstache.sha256sum
-
Set execute permission:
chmod +x smallstache
-
Move to directory from
PATH
environment variable:mv smallstache /usr/local/bin/
git clone [email protected]:macie/smallstache.sh.git
cd smallstache.sh
make install
Use make
(GNU or BSD):
make
- run checksmake test
- run testmake check
- perform static code analysismake install
- install in/usr/local/bin
make dist
- prepare for distributingmake clean
- remove distributed artifactsmake cli-release
- tag latest commit as a new releasemake info
- print system info (useful for debugging).
smallstache
is versioned according to the scheme YY.0M.MICRO
(calendar versioning). Releases are tagged in Git.
smallstache
handles limited length of key-value pairs. When you exceed
the limit, you will see an error such as:
smallstache[41]: sed: Argument list too long
As a workaround, fill template in parts with following steps:
# save key-value pairs to a few parts
set >data
split -l 2000 -a 5 data data_part_
# fill the template
cp template result
for part in data_part_*; do
smallstache result <"$part" >partially_filled
cp partially_filled result
done
# see the result
cat result
For more information, see ARG_MAX, maximum length of arguments for a new process.
smallstache
uses special character to separate key-value pairs in substitution
command (default: |
). When value contains this character, smallstache
will
throw an error similar to:
sed: -e expression #1, char 24: unknown option to `s'
In such case, you should use another character as a delimiter, for example:
smallstache -d _
.