- Notifications
You must be signed in to change notification settings - Fork47
Standalone string interpolator and template processor
License
gliderlabs/sigil
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Standalone string interpolator and template processor
echo'${name} is{{ range seq ${count:-3} }} cool{{ end }}!'| sigil -p name=Sigil
Sigil is cool cool cool!
Sigil is a command line tool for template processing and POSIX-compliantvariable expansion. It was created for configuration templating, but can be usedfor any text processing.
curl -L"https://github.com/gliderlabs/sigil/releases/download/v0.10.0/gliderlabs-sigil_0.10.0_$(uname -sm|tr\ _).tgz" \| tar -zxC /usr/local/bin
Other releases can be downloaded fromGithub Releases.
Template text can be provided via STDIN or from a file if provided with the-f
flag. Any other arguments are key-values in the form<key>=<value>
. They areused as variables.
echo 'Hello, $name' | sigil -p name=Jeff
sigil -p -f config.tmpl var1=foo "var2=Hello world"
There are two forms of variable syntax in Sigil. The first is POSIX style, whichamong other features allows default values or enforces required values:
$variable
- normal POSIX style${variable:-"default"}
- expansion with default value${variable:?}
- fails when not set
Environment variables are also available as POSIX style variables. This makesSigil great for quick and simple string interpolation.
The other syntax to use variables is consistent with the rest of the templatingsyntax. It uses{{
and}}
to define template expressions. Variable expansionin this form is simply used as:
{{ $variable }}
You can do much more with this syntax, such as modifier pipelines. All of whichis explained below.
Sometimes you want to use sigil to generate text, which uses golang templating itself.For example if you want to generatepacker configurationyour template might contain a lot of{{
and}}
.
Instead of replacing all{{
with{{“{{”}}
, you can change the delimiters,by setting theSIGIL_DELIMS
environment variable. It is the left and rightdelimiter strings, separated by a coma.
SIGIL_DELIMS={{{,}}} sigil -i'hello {{{ $name }}}' name=packer
There are a number of builtin functions that can be used as modifiers,conditional tests, expansion data sources, and more. There are two referencesfor functions available:
Here are a few examples:
{{ $variable | capitalize }}
{{ include "file.tmpl" "var1=foo" "var2=bar" }}
{{ file "example.txt" | replace "old" "new" }}
{{ json "file.json" | pointer "/Widgets/0/Name" }}
{{ if expr }} true {{ end }}
{{ if expr }} true {{ else }} false {{ end }}
{{ if expr }} true {{ else if expr }} also true {{ end }}
{{ range expr }} element: {{.}} {{ end }}
{{ range expr }} elements {{ else }} no elements {{ end }}
Lots more is possible with this template syntax. Sigil is based on Go'stext/template package. You can read fulldocumentation there.
About
Standalone string interpolator and template processor
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors12
Uh oh!
There was an error while loading.Please reload this page.