• Stars
    star
    413
  • Rank 104,801 (Top 3 %)
  • Language
    Go
  • License
    BSD 3-Clause "New...
  • Created over 9 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Standalone string interpolator and template processor

Sigil

CircleCI IRC Channel

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-compliant variable expansion. It was created for configuration templating, but can be used for any text processing.

Getting Sigil

curl -L "https://github.com/gliderlabs/sigil/releases/download/v0.9.0/gliderlabs-sigil_0.9.0_$(uname -sm|tr \  _).tgz" \
    | tar -zxC /usr/local/bin

Other releases can be downloaded from Github Releases.

Using Sigil

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 are used as variables.

  • echo 'Hello, $name' | sigil -p name=Jeff
  • sigil -p -f config.tmpl var1=foo "var2=Hello world"

Variables

POSIX style

There are two forms of variable syntax in Sigil. The first is POSIX style, which among 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 makes Sigil great for quick and simple string interpolation.

Template style

The other syntax to use variables is consistent with the rest of the templating syntax. It uses {{ and }} to define template expressions. Variable expansion in this form is simply used as:

  • {{ $variable }}

You can do much more with this syntax, such as modifier pipelines. All of which is explained below.

Custom Delimiters

Sometimes you want to use sigil to generate text, which uses golang templating itself. For example if you want to generate packer configuration your template might contain a lot of {{ and }}.

Instead of replacing all {{ with {{“{{”}}, you can change the delimiters, by setting the SIGIL_DELIMS environment variable. It is the left and right delimiter strings, separated by a coma.

SIGIL_DELIMS={{{,}}}  sigil -i 'hello {{{ $name }}}' name=packer

Functions

There are a number of builtin functions that can be used as modifiers, conditional tests, expansion data sources, and more. There are two references for 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" }}

Conditionals

  • {{ if expr }} true {{ end }}
  • {{ if expr }} true {{ else }} false {{ end }}
  • {{ if expr }} true {{ else if expr }} also true {{ end }}

Loops / Iteration

  • {{ range expr }} element: {{.}} {{ end }}
  • {{ range expr }} elements {{ else }} no elements {{ end }}

Full Syntax

Lots more is possible with this template syntax. Sigil is based on Go's text/template package. You can read full documentation there.

License

BSD

More Repositories

1

docker-alpine

Alpine Linux Docker image. Win at minimalism!
Shell
5,699
star
2

registrator

Service registry bridge for Docker with pluggable adapters
Go
4,661
star
3

logspout

Log routing for Docker container logs
Go
4,645
star
4

ssh

Easy SSH servers in Golang
Go
3,634
star
5

herokuish

Utility for emulating Heroku build and runtime tasks in containers
Shell
1,434
star
6

docker-consul

Dockerized Consul
Shell
1,070
star
7

connectable

Magic proxy for internal services
Go
464
star
8

resolvable

Host-level DNS gateway for Docker
Go
314
star
9

sshfront

Programmable SSH frontend
Go
301
star
10

com

Library for structuring Golang applications into components
Go
90
star
11

hostlocal

Host-level localhost for containers
69
star
12

hostctl

Opinionated CLI utility for easily provisioning cloud VMs
Go
35
star
13

stdcom

Re-usable Go components and micro-frameworks
Go
33
star
14

glidergun

Shell
31
star
15

cmd

Go
28
star
16

cellstack

DEPRECATED
Shell
23
star
17

pagebuilder

HTML
16
star
18

slack

JavaScript
15
star
19

comlab

Glider Labs app framework and development utility
Go
15
star
20

python-runtime

DEPRECATED
Shell
13
star
21

dockerbox

Container that runs a Docker daemon configured for running user code.
Go
13
star
22

infra.gl

DEPRECATED
HCL
12
star
23

kube-certdaemon

Simple daemon to fetch and refresh Let's Encrypt certs stored in k8s secrets
Go
7
star
24

glu

Glider Labs Utility, DEPRECATED
Go
7
star
25

gliderlabs.github.io

JavaScript
4
star
26

glidergun-rack

Shell
4
star
27

exp

Experimental projects and PoCs
Go
2
star
28

pkg

Go
2
star
29

ci

CI environment for Glider Labs projects
1
star
30

bigtoy

Glider Labs Semantic UI theme
1
star
31

gliderlabs.io

JavaScript
1
star
32

dns

HCL
1
star