Crates.io | kapow |
lib.rs | kapow |
version | |
source | src |
created_at | 2023-02-21 15:36:29.159177+00 |
updated_at | 2025-02-20 22:34:13.807893+00 |
description | Template processor |
homepage | |
repository | https://github.com/qtfkwk/kapow |
max_upload_size | |
id | 790807 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Kapow is a template processor that provides the following directives to support injecting file contents, command output, current date/time, elapsed time, etc in generated output.
It can be used in some different ways:
kapow [OPTIONS] path/to/file.ext
; optionally save the output via
redirection: kapow [OPTIONS] path/to/file.ext >output.ext
#!/usr/bin/env kapow
as the first line of a (Markdown) file,
make it "executable" via chmod +x file.ext
, then run via ./file.ext
(see
note #3 under block directives).
Use env's -S
option if passing options to kapow, for example:
#!/usr/bin/env -S kapow -w 60
.
See build.md
for an example.While kapow is designed around Markdown syntax, it can be used with any text format that works with its directives.
Directive | Description |
---|
!inc:path
| Include file contents; path is relative to its containing file
!run:command
| Run command and insert stdout
!start:name
- !stop:name
| Optional content included only if name
is provided in -f
value
Notes:
./file.ext
.!run
directive fails, kapow prints the error and stops processing,
unless the user specifies the -k
option.Directive | Example | Description |
---|
`!elapsed`
| 0s | Processing time
`!now`
| 2025-02-20T22:33:34Z | Current date/time in UTC / RFC 3339
`!now:local`
| Thu 20 Feb 2025 17:33:34 EST | Current date/time in local timezone
`!now:local:%A %H:%M`
| Thursday 17:33 | Current date/time in local timezone and custom format
`!now:MST7MDT`
| Thu 20 Feb 2025 15:33:34 MST | Current date/time in custom timezone
`!now:MST7MDT:%A %H:%M`
| Thursday 15:33 | Current date/time in custom timezone and format
`!now:US/Hawaii`
| Thu 20 Feb 2025 12:33:34 HST | Current date/time in custom locale
`!now:US/Hawaii:%A %H:%M`
| Thursday 12:33 | Current date/time in custom locale and format
`!now:UTC:%A %H:%M`
| Thursday 22:33 | Current date/time in UTC and custom format
`!now:x`
| Xj1JMXY | Current date/time in "x" format
`!today`
| 2025-02-20 | Current date in UTC / RFC 3339
`!today:local`
| 2025-02-20 | Current date in local timezone
`!today:MST7MDT`
| 2025-02-20 | Current date in custom timezone
`!today:MST7MDT:%e-%b-%Y`
| 20-Feb-2025 | Current date in custom timezone and format
`!today:US/Hawaii`
| 2025-02-20 | Current date in custom locale
`!today:US/Hawaii:%m/%d/%y`
| 02/20/25 | Current date in custom locale and format
`!today:UTC:%A`
| Thursday | Current date in UTC and custom format
!
with a backslash: \!
.\
and it will be
unwrapped in the output; this enables an author to wrap long lines in the
source but have them be unwrapped by kapow.
If trailing backslash(es) need to be maintained, add an additional backslash
and the line will not be unwrapped and the extra backslash will be removed.
) with a local
path are processed relative to the containing file, unless the -R
option is
used to disable this feature.cargo install kapow bat
NOTE: Installing bat
is optional, but if installed, kapow uses it for syntax
highlighting and paging (if on a Linux, macOS, or UNIX system; see the -p
,
-P
, -H
, -l
, and -r
options); also it's a nice utility to have around.
$ kapow -V
kapow 2.21.2
$ kapow -h
KAPOW!
Usage: kapow [OPTIONS] [PATH]...
Arguments:
[PATH]... Source file(s) [default: -]
Options:
-f <FLAGS> Flags (comma-separated list of flags to enable)
-p Page output
-P Do not page output
-H Disable syntax highlighting
-L Display all syntax highlight languages
-l <LANG> Syntax higlight language [default: md]
-w <WRAP> Wrap !run directive columns [default: 0]
-c <STRING> Wrap !run directive continuation [default: \]
-k Ignore !run directive failures
-R Disable relative image paths
-r, --readme Print readme
-h, --help Print help
-V, --version Print version
Code | Description |
---|---|
101 | Could not read input file |
102 | Could not read included file |
103 | Could not change directory |
104 | !run directive command failed |
NOTE: The kapow process may not appear to have exited with these error codes
in "normal usage" because output is piped to bat
as a pager if it is
installed and output is a TTY and unfortunately bat
masks the error code.
See the readme
task in Makefile.toml
:
t/VERSION.md
from t/VERSION.t.md
!run:../target/release/kapow -V
t/USAGE.md
from t/USAGE.t.md
!run:../target/release/kapow -h
README.md
from t/README.md
!inc:VERSION.md
!inc:USAGE.md
`!now`
(all variants)Please find the CHANGELOG.md
in the repository.
cargo install b3sum bat cargo-audit cargo-edit cargo-make \
cargo-outdated dtg kapow miniserve