Cleanup after the LLM: describe the var() function :)

Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
2026-11-27 14:21:37 +00:00
parent 9337f84976
commit b94817970b
+45 -4
View File
@@ -2,8 +2,8 @@
Yet another service manager. Yet another service manager.
Services are BASH scripts that get *sourced* by `ssm`. Same pitfalls apply — Services are BASH scripts with a tiny DSL that get *sourced* by `ssm`. Same
keep complex logic out of them. pitfalls apply — keep complex logic out of them.
## Install ## Install
@@ -59,7 +59,7 @@ Everything after `--` is treated as a literal service argument.
## Service files ## Service files
Each service is a plain BASH script: Each service is a BASH script written in a tiny DSL (see `var()` below), pure BASH is supported:
```bash ```bash
#!/usr/bin/env ssm #!/usr/bin/env ssm
@@ -136,10 +136,51 @@ Optional (defaults shown):
is equivalent to `service_oneshot = yes` and `service_respawn = 1` is is equivalent to `service_oneshot = yes` and `service_respawn = 1` is
equivalent to `always`. equivalent to `always`.
## `var()`
Everything ssm sources — the global config, service files and `functions/`
snippets — runs inside ssm's shell, where the built-in `var()` helper is
available. `var` turns an array-valued bash variable into a small ad-hoc
interface: `var <name>` creates a `<name>` accessor function (and
`<name>++` / `<name>--`) that acts on an array variable of the same name.
Declared functions are read-only. Using the accessor bare tests truthiness;
other operators are evaluated in place and leave their result in `$?`, e.g.
under `if`/`&&`/`||`.
```bash
var timeout = 5 # set (values become an array)
var service_args = -a --long-arg "parameter"
service_args u --long-arg # membership in the array
timeout == 5 # compare first element against a value
timeout =~ '^[0-9]+$' # regex match
```
Operators:
* `var name = value [value...]` — set the variable (it becomes a bash array).
* `var name += value [value...]` — append values.
* `var name _= value [value...]` — prepend values.
* `var name := value [value...]` — set only if the variable is unset or empty.
* `var name == value` — exit 0 if the variable's first element equals `value`.
* `var name =~ regex` — exit 0 if the variable's first element matches `regex`.
* `var name is file` / `is dir` / `is directory` / `is fs_object` / `is empty` —
filesystem-style tests on the value.
* `var name u value` — exit 0 if `value` is one of the array's elements.
* `var name` — no operator: exit 0 unless the variable is unset, empty, or
`false`/`0` (compared case-insensitively).
* `name++` / `name--` — increment/decrement the first element.
* `var name -v other_name` — build the accessor for `other_name` instead of
`name` (so `name` acts on `other_name`).
`var` is how ssm does this itself (e.g. `cgroups`, `service_cgroup_path is dir`,
`service_cgroup_procs is empty`) — feel free to use it in service files and the
global config.
## Global config ## Global config
`/etc/ssm/ssm.conf` (system) and `$XDG_CONFIG_HOME/ssm/ssm.conf` (user). `/etc/ssm/ssm.conf` (system) and `$XDG_CONFIG_HOME/ssm/ssm.conf` (user).
Since it is sourced, it is plain BASH: Since it is sourced, it is a BASH script with a DSL (see `var()` above):
```bash ```bash
# Enable cgroup-related features (experimental, cgroups v2) # Enable cgroup-related features (experimental, cgroups v2)