| Crates.io | shinkansen |
| lib.rs | shinkansen |
| version | 0.2.0 |
| created_at | 2025-12-16 19:47:25.975837+00 |
| updated_at | 2025-12-26 19:53:28.574322+00 |
| description | A CLI file preprocessor using MiniJinja templates |
| homepage | |
| repository | https://github.com/bbeardsley/shinkansen |
| max_upload_size | |
| id | 1988528 |
| size | 1,056,412 |
A fast, cross-platform command-line file preprocessor built with Rust that uses MiniJinja templates to transform files with dynamic variables.
--env flaggit clone https://github.com/bbeardsley/shinkansen
cd shinkansen
cargo build --release
# Binary will be at ./target/release/shinkansen
just install
This installs the binary to your Cargo bin directory (typically ~/.cargo/bin).
Add the binary to your PATH or use it directly:
./target/release/shinkansen --help
Process a single template file with CLI variables:
shinkansen template.txt -D name="John" -D app="MyApp" -o -
JSON Config (config.json):
{
"name": "Alice",
"version": "1.0.0",
"environment": "production"
}
shinkansen template.txt -c config.json -o output.txt
YAML Config (config.yaml):
name: Bob
version: "2.0.0"
debug: true
shinkansen template.txt -c config.yaml -o -
TOML Config (config.toml):
name = "Charlie"
version = "3.0.0"
features = ["auth", "api"]
shinkansen template.txt -c config.toml -o output.txt
echo "Hello, {{ name }}!" | shinkansen - -D name="World"
# Output: Hello, World!
# Explicit stdout with -o -
echo "Hello, {{ name }}!" | shinkansen - -D name="World" -o -
Variables are layered with increasing precedence:
--env, lowest)export GREETING="Hi"
shinkansen template.txt -c config.yaml --env="GREETING" -D GREETING="Hello" -o -
# CLI value "Hello" wins
Load specific environment variables:
shinkansen template.txt --env="PATH,HOME,USER" -o -
When using -D flag or environment variables, you can escape special
characters:
\\ - escaped backslash\, - escaped comma\= - escaped equals\[ - escaped left bracket\] - escaped right bracket\{ - escaped left curly brace\} - escaped right curly braceExamples:
# Escape curly brackets in command line
shinkansen template.txt -D "message=Hello\{world\}"
# Escape multiple characters
shinkansen template.txt -D "data=key\=value\,more\\data"
# Environment variables with escaping
export VAR="test\{curly\}brackets"
shinkansen template.txt --env VAR
Environment variables are not loaded automatically. You must explicitly
specify which variables to load using the --env flag. Multiple variables can
be specified as a comma-separated list.
Process all files in a directory (non-recursive):
shinkansen templates/ -o output/ -D env="prod"
Process directory recursively:
shinkansen templates/ -r -o output/ -c config.json
Directory structure is preserved in the output:
templates/
├── app.conf
└── services/
└── api.conf
→ output/
├── app.conf
└── services/
└── api.conf
shinkansen file1.txt file2.txt file3.txt -o output_dir/ -D version="1.0"
To stdout (default for single input):
shinkansen template.txt -D var="value"
# Or explicitly with -o -
shinkansen template.txt -D var="value" -o -
To a specific file:
shinkansen template.txt -D var="value" -o result.txt
To a directory:
shinkansen template.txt -D var="value" -o output/
# Creates output/template.txt
Shinkansen uses MiniJinja templates. Here are some common patterns:
Hello, {{ name }}!
Version: {{ version }}
{{ name | upper }}
{{ email | default(value="no-email") }}
{{ price | round(precision=2) }}
{% if debug %}
Debug mode is ON
{% else %}
Production mode
{% endif %}
{% for item in items %}
- {{ item }}
{% endfor %}
{# This is a comment and won't appear in output #}
For complete MiniJinja syntax documentation, see: https://docs.rs/minijinja/latest/minijinja/
| Input Type | Valid Output Options |
|---|---|
| Single file | File, directory, or stdout |
| Multiple files | Directory only |
| Directory | Directory only |
| Stdin | File, directory, or stdout |
Generate configuration files for different environments:
# Development
shinkansen app.conf.template -c dev.yaml -o config/dev/app.conf
# Production
shinkansen app.conf.template -c prod.yaml -o config/prod/app.conf
shinkansen api_template.rs -c schema.json -o src/generated/api.rs
shinkansen README.template.md -D version="1.2.3" -D date="2024-01-15" -o README.md
shinkansen templates/ -r -c project.yaml -o output/
The project is designed to be cross-platform.
Linux:
cargo build --release
macOS:
cargo build --release
Windows:
cargo build --release
Cross-compilation:
# For Windows from Linux/macOS
cargo build --release --target x86_64-pc-windows-msvc
Shinkansen provides helpful error messages for common issues:
See the examples/ directory for complete, working examples:
Run examples directly:
# Simple template with CLI variables
./target/release/shinkansen examples/project.md.template \
-D project_name="My Project" \
-D version="2.0.0" \
-o -
# Using config file
./target/release/shinkansen examples/project.md.template \
-c examples/config.json \
-o -
MIT License - see repository for details.
If you see Variable 'x' not found in context, ensure:
-D, config file, or environmentdefault filter for optional variables:
{{ var | default(value="fallback") }}When processing multiple files, specify an output directory:
shinkansen file1.txt file2.txt -o output_dir/