https://github.com/tmc/tmpl
  
  
    tmpl - unix-friendly templating tool. 
    https://github.com/tmc/tmpl
  
helm unix
        Last synced: 7 months ago 
        JSON representation
    
tmpl - unix-friendly templating tool.
- Host: GitHub
 - URL: https://github.com/tmc/tmpl
 - Owner: tmc
 - License: isc
 - Created: 2015-08-20T20:58:39.000Z (about 10 years ago)
 - Default Branch: master
 - Last Pushed: 2022-06-30T01:30:25.000Z (over 3 years ago)
 - Last Synced: 2025-03-24T09:52:47.318Z (7 months ago)
 - Topics: helm, unix
 - Language: Go
 - Homepage:
 - Size: 40 KB
 - Stars: 24
 - Watchers: 2
 - Forks: 2
 - Open Issues: 0
 - 
            Metadata Files:
            
- Readme: README.in
 - License: LICENSE
 - Security: SECURITY.md
 
 
Awesome Lists containing this project
README
          # tmpl
Command tmpl renders a template with the current env vars as input.
tmpl packs a punch in under 200 lines of code: a single static binary supplies the capabilities of
many more complicated templating engines.
It's especially helpful as an early entrypoint into containers to prepare configuration files.
```sh
$ tmpl -h
{{.HELP}}
```
It effectively exposes Go's [text/template](http://golang.org/pkg/text/template) for use in shells.
Reference [text/template](http://golang.org/pkg/text/template) documentation for template language specification.
It includes all of the template helpers from [sprig](https://godoc.org/github.com/Masterminds/sprig).
## Safe Dockerfile Inclusion
To safely include in your build pipelines:
```Dockerfile
FROM ubuntu:bionic
RUN apt-get update
RUN apt-get install -y curl
ARG TMPL_URL=https://github.com/tmc/tmpl/releases/download/{{ .LATEST_TAG }}/tmpl_linux_amd64
ARG TMPL_SHA256SUM={{ .LINUX_SHASUM }}
RUN curl -fsSLo tmpl ${TMPL_URL} \
		&& echo "${TMPL_SHA256SUM}  tmpl" | sha256sum -c - \
		&& chmod +x tmpl && mv tmpl /usr/local/bin/tmpl
```
## Safe Shell Scripting Inclusion
To safely include in your shell scripts:
```bash
#!/bin/bash
set -euo pipefail
# Helper Functions
case "${OSTYPE}" in
linux*) platform=linux
	;;
darwin*)
	platform=darwin
	;;
*) platform=unknown ;;
esac
function install_tmpl() {
  if [[ "${platform}" == "darwin" ]]; then
    TMPL_SHA256SUM={{ .MACOS_SHASUM }}
  else
    TMPL_SHA256SUM={{ .LINUX_SHASUM }}
  fi
  TMPL_URL=https://github.com/tmc/tmpl/releases/download/{{ .LATEST_TAG }}/tmpl_${platform}_amd64
  curl -fsSLo tmpl ${TMPL_URL} \
    && echo "${TMPL_SHA256SUM}  tmpl" | sha256sum -c - \
    && chmod +x tmpl
  mv tmpl /usr/local/bin/tmpl || echo "could not move tmpl into place"
}
command -v tmpl > /dev/null || install_tmpl
```
### Example 1
Given a file 'a' with contents:
	{{"{{"}} range $key, $value := . {{"}}"}}
	  KEY:{{"{{"}} $key {{"}}"}} VALUE:{{"{{"}} $value {{"}}"}}
	{{"{{"}} end {{"}}"}}
Invoking
	$ cat a | env -i ANSWER=42 ITEM=Towel `which tmpl`
Produces
	KEY:ANSWER VALUE:42
	
	KEY:ITEM VALUE:Towel
### Example 2
Given a file 'b' with contents:
	VERSION={{"{{"}}.HEAD{{"}}"}}
Invoking
	$ cat b | HEAD="$(git rev-parse HEAD)" tmpl
Produces
	VERSION=4dce1b0a03b59b5d63c876143e9a9a0605855748
### Example 3
Given a directory via the `-r` flag, tmpl recurses, expanding each path and file and produces a tarball to the output destination.
Invoking
    $ mkdir testdata/recursive-out
	$ tmpl -r testdata/recursive-example | tar -C testdata/recursive-out --strip-components=2 -xvf -
	$ cat testdata/recursive-out/user-tmc
Produces (for me, at time of writing)
	For the current user tmc:
	Shell: /bin/bash
	EDITOR: vim
	😎