Skip to content

Reference

Script Writers ​

Create executable scripts from your Lua configuration. Rootbeer adds the interpreter line and makes the file executable when you run rb apply.

lua
local rb = require("rootbeer")

rb.scripts.bash("~/.local/bin/hello", [[
  echo "hello $1"
]])

rb.scripts.python("~/.local/bin/greet", [[
  import sys
  print(f"hello, {sys.argv[1] if len(sys.argv) > 1 else 'world'}")
]])

The interpreter must be installed and available on PATH when the script runs. Rootbeer does not check or lint the script body.

Custom interpreters ​

Use rb.scripts.script(interpreter, path, body) for languages without a named helper, or to pin a specific interpreter path:

lua
rb.scripts.script("awk", "~/.local/bin/sum", [[
  { total += $1 } END { print total }
]])

rb.scripts.script("/opt/homebrew/bin/python3.12", "~/.local/bin/pinned", [[
  import sys; print(sys.version)
]])

A bare command ("awk") becomes #!/usr/bin/env awk. An absolute path (/opt/homebrew/bin/python3.12) is used verbatim as the shebang.

API ​

rootbeer.scripts.bash(path, body) ​

Writes an executable Bash script (#!/usr/bin/env bash). Defers a WriteFile op for the body and a Chmod op (mode 0755).

Parameters

pathstring
Destination file path.
bodystring
Script body.

rootbeer.scripts.fish(path, body) ​

Writes an executable Fish script (#!/usr/bin/env fish).

Parameters

pathstring
Destination file path.
bodystring
Script body.

rootbeer.scripts.lua(path, body) ​

Writes an executable Lua script (#!/usr/bin/env lua).

Parameters

pathstring
Destination file path.
bodystring
Script body.

rootbeer.scripts.node(path, body) ​

Writes an executable Node.js script (#!/usr/bin/env node).

Parameters

pathstring
Destination file path.
bodystring
Script body.

rootbeer.scripts.nu(path, body) ​

Writes an executable Nushell script (#!/usr/bin/env nu).

Parameters

pathstring
Destination file path.
bodystring
Script body.

rootbeer.scripts.perl(path, body) ​

Writes an executable Perl script (#!/usr/bin/env perl).

Parameters

pathstring
Destination file path.
bodystring
Script body.

rootbeer.scripts.python(path, body) ​

Writes an executable Python 3 script (#!/usr/bin/env python3).

Parameters

pathstring
Destination file path.
bodystring
Script body.

rootbeer.scripts.ruby(path, body) ​

Writes an executable Ruby script (#!/usr/bin/env ruby).

Parameters

pathstring
Destination file path.
bodystring
Script body.

rootbeer.scripts.script(interpreter, path, body) ​

Generic script writer with a custom interpreter shebang. Use a bare command ("bash") which becomes #!/usr/bin/env bash, or an absolute path ("/bin/sh") which is used verbatim. Prefer the named helpers (bash, python, …) for common languages.

Parameters

interpreterstring
Bare command name or absolute interpreter path.
pathstring
Destination file path (~ is expanded).
bodystring
Script body. A trailing newline is added if missing.

rootbeer.scripts.sh(path, body) ​

Writes an executable POSIX sh script (#!/usr/bin/env sh).

Parameters

pathstring
Destination file path.
bodystring
Script body.

rootbeer.scripts.zsh(path, body) ​

Writes an executable Zsh script (#!/usr/bin/env zsh).

Parameters

pathstring
Destination file path.
bodystring
Script body.