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>:

nu
# tools/greet.nu
# Print a greeting for name
def main [name: string, --upper] {
  let msg = $"Hello, ($name)!"
  if $upper { $msg | str upcase } else { $msg }
}
sh
tola nu tools/greet.nu "Tola" --upper
tola nu tools/greet.nu --help

Place 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:

ImportPurpose
use tola get-siteRead site config, options, and directory paths.
use tola get-moduleRead the active module instance, or get-module <alias>.
use tola queryRun module queries (<alias>.<name>) or standalone .typ query files.
use tola get-contextRead the full invocation context (paths, options, stage, reportPath).
use tola get-hookRead hook stage and directories, or get-hook --rerun-on-digest.
use tola get-assetsRead the resolved asset snapshot after discovery (--module/--include/--exclude).
use tola get-initRead output-dir, target-dir, and interactive inside [init].
use tola diagnosticmake, submit (hooks/commands), and render (scripts) structured diagnostics.
use tola imageInspect metadata and resize raster images or SVGs with no external binary.
use tola terminalInteractive terminal table picker pick.
use tola syntax-highlightSyntax-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:

nu
use tola image
image resize photo.png --output thumb.webp --width 640 --format webp

Specifying 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:

sh
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 render

See Scripts for full command options.

Interactive picker

Combine terminal pick and syntax-highlight inside author-facing interactive commands (never inside unattended build hooks):

nu
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 main parameters and comments so --help generates automatically. Never call main at the bottom of the script or write files at top level so --help stays side-effect-free; send progress messages to print --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 .typ files with open --raw and pass save --force only when overwriting intentionally.
  • Subprocesses and paths: Run external programs via ^$prog ...$args | complete and inspect $r.exit_code; invoke Tola recursively via $env.TOLA_EXECUTABLE forwarding --config, --offline, and --pure. Join paths with path join, locate script-adjacent files with $env.FILE_PWD or path self, and site files from (get-site).root.

Test shared helpers in the same runtime with Nushell’s std/assert:

nu
use std/assert
use ./helpers.nu slug-name

def main [] {
  assert equal (slug-name "Hello Tola") "hello-tola"
}

Search this site

Use the arrow keys to move through results.

Type to search.