Nushell scripts
Tola embeds a pinned Nushell runtime that ignores host user configs and plugins so build hooks, helper scripts, and module commands behave identically across machines. Client-side browser behavior still uses JavaScript.
Runtime
tola nu runs local .nu files, built-in scripts @tola-scripts/<name>, or modules with [nu] entry via @tola-modules/<alias>:
# tools/greet.nu
# Print a greeting for name
def main [name: string, --upper] {
let msg = $"Hello, ($name)!"
if $upper { $msg | str upcase } else { $msg }
}tola nu tools/greet.nu "Tola" --upper
tola nu tools/greet.nu --helpPlace Tola options (--config FILE, --stdin) before the script target and script arguments after it (tola nu has no -c flag). Pass --stdin when reading piped input and decode inside the script with $in | from json.
Running a .nu path directly preserves your current working directory while searching upward for tola.toml; module subcommands and @tola-modules/<alias> always run in the site root. Neither triggers build hooks.
When a module sets [nu] entry = "tools/mod.nu", other scripts can use tola-modules <alias> to import its export def functions; exporting export def main also makes tola nu @tola-modules/<alias> directly runnable.
Built-in tola library
Run tola nu --help to see every library available inside the runtime:
| Import | Purpose |
|---|---|
use tola get-site | Read site config, options, and directory paths. |
use tola get-module | Read the active module instance, or get-module <alias>. |
use tola query | Run module queries (<alias>.<name>) or standalone .typ query files. |
use tola get-context | Read the full invocation context (paths, options, stage, reportPath). |
use tola get-hook | Read hook stage and directories, or get-hook --rerun-on-digest. |
use tola get-assets | Read the resolved asset snapshot after discovery (--module/--include/--exclude). |
use tola get-init | Read output-dir, target-dir, and interactive inside [init]. |
use tola diagnostic | make, submit (hooks/commands), and render (scripts) structured diagnostics. |
use tola image | Inspect metadata and resize raster images or SVGs with no external binary. |
use tola terminal | Interactive terminal table picker pick. |
use tola syntax-highlight | Syntax-highlight preview text in the terminal. |
use tola-modules <alias> | Import exported Nu helpers from a configured module. |
For example, resize and convert an image with built-in image:
use tola image
image resize photo.png --output thumb.webp --width 640 --format webpSpecifying either width or height preserves aspect ratio; specifying both crops to fit (controlled via --anchor). The target parent directory must exist and existing files are not overwritten.
Built-in scripts
Three scripts are also callable directly from the shell or external pipelines:
tola nu @tola-scripts/image metadata photo.png
tola nu @tola-scripts/image resize photo.png -o preview.webp --width 640 --format webp
tola check --json | tola nu --stdin @tola-scripts/diagnostic renderSee Scripts for full command options.
Interactive picker
Combine terminal pick and syntax-highlight inside author-facing interactive commands (never inside unattended build hooks):
use tola [terminal syntax-highlight]
let rows = [
{name: "Overview", file: "content/en/docs/start/overview.typ"}
{name: "Quick start", file: "content/en/docs/start/quick-start.typ"}
]
let picked = (
$rows
| terminal pick --columns [name] --fuzzy
--preview {|row| open --raw $row.file | syntax-highlight typst }
)
if ($picked | is-not-empty) { $picked | first }pick returns the full selected record list (including hidden columns), or [] when cancelled or empty; add --multi for multi-select. Keep preview closures strictly read-only.
Testing
- Parameters and side effects: Annotate
def mainparameters and comments so--helpgenerates automatically. Never callmainat the bottom of the script or write files at top level so--helpstays side-effect-free; send progress messages toprint --stderr. - Data and I/O: Keep values as records and tables inside pipelines, serializing only when writing files (
to json | save --raw $dest); read text or.typfiles withopen --rawand passsave --forceonly when overwriting intentionally. - Subprocesses and paths: Run external programs via
^$prog ...$args | completeand inspect$r.exit_code; invoke Tola recursively via$env.TOLA_EXECUTABLEforwarding--config,--offline, and--pure. Join paths withpath join, locate script-adjacent files with$env.FILE_PWDorpath self, and site files from(get-site).root.
Test shared helpers in the same runtime with Nushell’s std/assert:
use std/assert
use ./helpers.nu slug-name
def main [] {
assert equal (slug-name "Hello Tola") "hello-tola"
}