A simple CLI tool for processing text templates with variable substitution from environment variables or user input.
Variables are resolved in the following order:
- Environment variables. If a variable exists in the environment, its value is used.
- Interactive prompt. If not found in environment, you'll be prompted to enter a value.
You can build it from source, or use go install
go install github.com/konyahin/sttemp@lateststtemp [options] [template-name ...]If you want to get autocomplete, copy appropriate line into your shell settings.
# zsh
autoload -Uz compinit
compinit
compdef '_values "sttemp options" $(sttemp -l 2>/dev/null)' sttemp
# bash
complete -W "$(sttemp -l 2>/dev/null)" sttemp
# ksh
set -A complete_sttemp -- $(sttemp -l)fzf integration can look like this
fst () {
templates="$(sttemp -l)"
selected=$(echo "$templates" | fzf)
[ -n "$selected" ] && sttemp "$selected"
}-C <path>custom template directory (default:~/.local/share/sttemp)-o <file>output to file instead of stdout-duse template's subdirectory name as output filename-hshow short help--no-inputuse only environment variables (do not ask user for substitution value); exit with error if some variable is missing--editedit selected template in your console$EDITOR-llist all templates names
sttemp # list all templates
sttemp greeting # process template `greeting`, output to stdout
sttemp -o out.txt greeting # save to file `out.txt`
sttemp -d mit # save as `LICENSE`, if `mit` in `LICENSE` subfolder (see files structure below)
sttemp --edit mit # open file with `mit` template in `$EDITOR`
export NAME="Alice" && sttemp greeting # use environment variablesUse {VARIABLE} for placeholders. Variables are resolved from environment or prompted interactively. To include literal {VARIABLE} text in your template without substitution, escape it with a backslash as this \{VARIABLE}.
Hello, {FIRST NAME}!
Server: {HOST}:{PORT}
Escape literals: \{NOT_A_VAR}
Store templates in subdirectories for auto-naming with -d:
~/.local/share/sttemp/
├── greeting
└── LICENSE/
├── mit # `sttemp -d mit` creates file "LICENSE"
└── GPLv3 # `sttemp -d GPLv3` also creates file "LICENSE"