Script Writers
Create executable scripts from your Lua configuration. Rootbeer adds the interpreter line and makes the file executable when you run rb apply.
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:
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
pathstringbodystringrootbeer.scripts.fish(path, body)
Writes an executable Fish script (#!/usr/bin/env fish).
Parameters
pathstringbodystringrootbeer.scripts.lua(path, body)
Writes an executable Lua script (#!/usr/bin/env lua).
Parameters
pathstringbodystringrootbeer.scripts.node(path, body)
Writes an executable Node.js script (#!/usr/bin/env node).
Parameters
pathstringbodystringrootbeer.scripts.nu(path, body)
Writes an executable Nushell script (#!/usr/bin/env nu).
Parameters
pathstringbodystringrootbeer.scripts.perl(path, body)
Writes an executable Perl script (#!/usr/bin/env perl).
Parameters
pathstringbodystringrootbeer.scripts.python(path, body)
Writes an executable Python 3 script (#!/usr/bin/env python3).
Parameters
pathstringbodystringrootbeer.scripts.ruby(path, body)
Writes an executable Ruby script (#!/usr/bin/env ruby).
Parameters
pathstringbodystringrootbeer.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
interpreterstringpathstring~ is expanded).bodystringrootbeer.scripts.sh(path, body)
Writes an executable POSIX sh script (#!/usr/bin/env sh).
Parameters
pathstringbodystringrootbeer.scripts.zsh(path, body)
Writes an executable Zsh script (#!/usr/bin/env zsh).
Parameters
pathstringbodystring