About

Kapow is a template processor that provides the following directives to support injecting file contents, command output, current date/time, etc in generated files.

It can be used in a few different ways:

Kapow is generally designed around the idea of using Markdown output formatting, but the format could be any text format that supports the desired syntax.

NOTE: Installing [bat] and piping kapow output to bat -pl md adds nice syntax highlighting to Markdown and paging (or add -P to disable the pager).

Block directives

Directive | Description ---|--- !inc:path | Include file contents; path is relative to its containing file !run:command | Run command and insert stdout

Notes:

  1. Block directives must be placed at the beginning of a line.
  2. Long commands can be backslash-wrapped.
  3. Keep in mind that file paths and commands are processed from the directory where the source file is located. That is unless the source file is stdin (including shebang usage), so changing to the directory where the source file is located is a good idea.

Span directives

Directive | Example | Description ---|---|--- `!elapsed` | 0s | Processing time `!now` | 2023-05-02T17:20:03Z | Current date/time in UTC / RFC 3339 `!now:local` | Tue 02 May 2023 13:20:03 EDT | Current date/time in local timezone `!now:local:%A %H:%M` | Tuesday 13:20 | Current date/time in local timezone and custom format `!now:MST7MDT` | Tue 02 May 2023 11:20:03 MDT | Current date/time in custom timezone `!now:MST7MDT:%A %H:%M` | Tuesday 11:20 | Current date/time in custom timezone and format `!now:US/Hawaii` | Tue 02 May 2023 07:20:03 HST | Current date/time in custom locale `!now:US/Hawaii:%A %H:%M` | Tuesday 07:20 | Current date/time in custom locale and format `!now:UTC:%A %H:%M` | Tuesday 17:20 | Current date/time in UTC and custom format `!now:x` | Xh41HK3 | Current date/time in "x" format `!today` | 2023-05-02 | Current date in UTC / RFC 3339 `!today:local` | 2023-05-02 | Current date in local timezone `!today:MST7MDT` | 2023-05-02 | Current date in custom timezone `!today:MST7MDT:%v` | 2-May-2023 | Current date in custom timezone and format `!today:US/Hawaii` | 2023-05-02 | Current date in custom locale `!today:US/Hawaii:%x` | 05/02/23 | Current date in custom locale and format `!today:UTC:%A` | Tuesday | Current date in UTC and custom format

Usage

text $ kapow -V kapow 2.5.0

```text $ kapow -h KAPOW!

Usage: kapow [OPTIONS] [INPUT_FILES]...

Arguments: [INPUT_FILES]... Input file(s) [default: -]

Options: -r, --readme Print readme -h, --help Print help -V, --version Print version ```

Errors

Code | Description ---|--- 101 | Could not read input file 102 | Could not read included file 103 | Could not change directory

Example

See the readme task in Makefile.toml:

Changelog

Development

bash cargo install bat cargo-edit cargo-make cargo-outdated dtg kapow \ miniserve