https://github.com/navrocky/muenvsubst
Substitutes environment variables like envsubst do but with powerful template engine
https://github.com/navrocky/muenvsubst
cplusplus envsubst inja jinja templating
Last synced: 5 months ago
JSON representation
Substitutes environment variables like envsubst do but with powerful template engine
- Host: GitHub
- URL: https://github.com/navrocky/muenvsubst
- Owner: navrocky
- Created: 2024-02-14T15:07:57.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2025-04-22T12:35:19.000Z (about 1 year ago)
- Last Synced: 2025-04-22T13:40:51.314Z (about 1 year ago)
- Topics: cplusplus, envsubst, inja, jinja, templating
- Language: C++
- Homepage:
- Size: 65.4 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# MuEnvSubst
Substitutes environment variables using one of the templating engines, as
[envsubst](https://www.gnu.org/software/gettext/manual/html_node/envsubst-Invocation.html) does, but using a powerfull templating engine.
This is a list of supported template engines:
- `inja` - [Inja templates](https://pantor.github.io/inja/)
One of the advantages of this utility is that it is built very small static binary without any dependencies.
Architecture of binary is Linux x86 (32 bit). It can be run in any Linux x86 and x86_64, both new and very old versions.
## Installation
Download and copy binary to any destination specified in `PATH` (~/bin, /usr/local/bin, /usr/bin).
Do not forget to set execution flag on binary with `chmod`.
```sh
sudo curl https://github.com/navrocky/muenvsubst/releases/download/1.5.0/muenvsubst -Lo /usr/local/bin/muenvsubst
sudo chmod +x /usr/local/bin/muenvsubst
```
## Usage
```
Substitutes environment variables using Inja templating engine, as envsubst
does.
USAGE: ./muenvsubst [ -h, --help ] [ -i, --in ] [ -d,
--include-dir ] [ -o, --out ] [ -v, --version ]
OPTIONAL:
-h, --help Print this help.
-i, --in Input file
-d, --include-dir The directory where the included files are searched
for. This argument can be specified more than once.
-o, --out Output file
-v, --version Output version information and exit
```
## Inja syntax
[Inja](https://pantor.github.io/inja/) inspired by Python's Jinja and supports subset of original Jinja syntax.
Inja syntax documented [here](https://pantor.github.io/inja/) and original Jinja syntax documented
[here](https://jinja.palletsprojects.com/en/stable/templates/).
Also supported function [pipe](https://jinja.palletsprojects.com/en/stable/templates/#filters) calling syntax.
These are equal expressions:
```
{{ split("A,B,C", ",") }}
{{ "A,B,C" | split(",") }}
{{ sh("198c126c-2691-463f-9708-1ee485ce4d68", "sed 's/-//g'") }}
{{ "198c126c-2691-463f-9708-1ee485ce4d68" | sh("sed 's/-//g'") }}
```
## Additional Inja functions
- [error](functions.md#error) - throws an error
- [fromBase64](functions.md#fromBase64) - decode base64 string
- [fromJson](functions.md#fromJson) - parse JSON string to object
- [sh](functions.md#sh) - execute shell script
- [split](functions.md#split) - splits text by delimiter
- [toBase64](functions.md#toBase64) - encode base64 string
- [toBool](functions.md#toBool) - convert any value to boolean
- [toJson](functions.md#toJson) - serialize value to JSON string
- [trim](functions.md#trim) - trims text
## More Inja examples
### Simple variable substitution
```sh
echo "Hello, {{ USER }}!" | muenvsubst
```
then output will be:
```
Hello, John!
```
### Using variable and function
```sh
muenvsubst <