Skip to content

Core API

The core API is available via require("rootbeer") and provides the primitives for writing files, creating symlinks, and querying system info.

lua
local rb = require("rootbeer")

Writing Files

Write content to any path. Parent directories are created automatically, and ~ expands to $HOME.

lua
rb.file("~/.config/starship.toml", [[
[character]
success_symbol = "[➜](bold green)"
]])

file(path, content)

Writes content to a file path. The ~ character is expanded to $HOME. Parent directories are created automatically. In dry-run mode, prints what would be written.

Parameters:

NameTypeDescription
pathstringThe destination file path (supports ~ expansion).
contentstringThe content to write.

Symlinking

Symlink files from your source directory into place. The source path is relative to ~/.local/share/rootbeer/source/. Idempotent — existing correct links are skipped, stale links are replaced.

lua
rb.link_file("config/gitconfig", "~/.gitconfig")
rb.link_file("config/nvim", "~/.config/nvim")

Creates a symlink from a source file to a destination path. The source is relative to the rootbeer source directory (~/.local/share/rootbeer/source/). The destination supports ~ expansion. Idempotent — existing correct links are left alone, stale links are replaced.

Parameters:

NameTypeDescription
srcstringSource path, relative to the source directory.
deststringDestination path (supports ~ expansion).

System Info

Query the current machine to write conditional configs that work across multiple systems.

lua
local d = rb.data()

if d.os == "Darwin" then
    rb.file("~/.config/homebrew/env", 'export HOMEBREW_PREFIX="/opt/homebrew"\n')
end

data()

Returns a table with information about the current machine.

Returns:

  • rb.DataInfo
NameTypeDescription
osstringOperating system name (e.g. "Linux", "Darwin").
archstringCPU architecture (e.g. "x86_64", "arm64").
hostnamestringMachine hostname.
homestringHome directory path.
usernamestringCurrent username.

JSON Serialization

Generate JSON config files for tools like VS Code or Alacritty.

lua
rb.file("~/.config/alacritty/alacritty.json", rb.to_json({
    terminal = { shell = "/bin/zsh" },
    font = { size = 14 },
}))

to_json(tbl)

Serializes a Lua table to a JSON string.

Parameters:

NameTypeDescription
tbltableThe table to serialize.

Returns:

  • string

Low-Level Primitives

These are building blocks used internally by modules. Prefer rb.file() with module renderers for most use cases.

line(str)

Appends a line (with trailing newline) to the internal output buffer. This is a low-level primitive — prefer rb.file() with module renderers like zsh.config() for most use cases.

Parameters:

NameTypeDescription
strstringThe line to append.

emit(str)

Appends raw text to the internal output buffer without a trailing newline.

Parameters:

NameTypeDescription
strstringThe text to append.

Utilities

interpolate_table(tbl, fn)

Passes a table through a transform function and returns the result.

Parameters:

NameTypeDescription
tbltableThe input table.
fnfun(tbl: table): tableThe transform function.

Returns:

  • table

register_module(name, tbl)

Registers a native Lua module under the given name. Used internally by the plugin system.

Parameters:

NameTypeDescription
namestringThe module name to register.
tbltableThe module table.