TOML 1.0 · Zsh 5.8+ · psh 1.0.0-rc6+
ztoml
Read TOML configuration directly from Zsh or psh. Source the library in your script to parse settings and look up typed values without starting subprocesses.
v0.1.1 parses configurations with many table headers and quoted keys faster while preserving precise error locations.
View on GitHubRead a setting
The next psh release will include ztoml in its standard installation. For Zsh and current psh releases, clone the repository into ./ztoml and save this configuration as settings.toml in the current directory.
[services."api.internal"]
ports = [8080, 8081]Pass each path segment as a separate argument. The key api.internal is one segment, and array indices start at 1. This example prints 8080 (integer).
source ./ztoml/ztoml.zsh
if ztoml_load ./settings.toml; then
if ztoml_get services 'api.internal' ports 1; then
print -r -- "$REPLY ($ZTOML_TYPE)"
fi
else
print -ru2 -- "$ZTOML_ERROR"
fiShell API
ztoml_load PATH- Read a TOML document from a regular file.
ztoml_parse TEXT [SOURCE]- Parse TOML text already stored in a shell variable.
ztoml_read FD [SOURCE]- Read from an open file descriptor through the end of the input.
ztoml_get [SEGMENT ...]- Return the node type in ZTOML_TYPE and its scalar value in REPLY.
ztoml_keys [SEGMENT ...]- Return table keys in insertion order or array indices in the reply array.
A successful read replaces the current document. If a read fails, the previous document stays available. For invalid TOML, ZTOML_ERROR gives the source, line, and byte column.