Skip to content

Writing an integration

An integration is one JSON manifest. Make your own from the UI (Integrations → New…, then Save as preset from the Bindings page, Save the look in use for a theme, Save as template from the hub editor) or by hand in ~/.config/virgul/integrations/<id>.json (a file of a built-in’s id replaces it).

{
"id": "obs", "name": "OBS Studio", "version": 1, "author": "you",
"icon": "camera", "os": ["linux", "windows", "darwin"],
"description": "Scenes, recording and streaming.",
"url": "https://obsproject.com",
"requires": [{ "command": "obs-cmd", "why": "talks to OBS", "install": "cargo install obs-cmd", "check": "obs-cmd --version" }],
"servers": { "obs": "virgul state-server --every 2s" },
"strings": { "en": { "rec": "Record" }, "fr": { "rec": "Enregistrer" } },
"templates": [],
"presets": [],
"themes": []
}
  • os: the systems it works on (none: all). requires: programs looked up in PATH, check/expect for the version, ready for a warning.
  • strings per language, used as %{t.key}.
{ "id": "record", "name": "Record", "version": 1, "kind": "item",
"params": [{ "key": "name", "label": "Name", "kind": "text", "default": "%{t.rec}" }],
"item": { "label": "%{name}", "icon": "lucide:circle-dot#ff4444", "action": "obs-cmd recording toggle",
"state": "obs-cmd recording status", "state_server": "obs" } }
  • kind: item (a bubble), hub, gesture, chord.
  • Params: text, bool, number, choice (options, or source — a state server query answering a JSON list), key; multiple, required, default, pattern, preselect.
  • Placeholders %{key}, %{key.field}, filters |q (shell-quoted — always for values going into commands), |json, |first, |count; "if": "path", {"each": …, "as": …, "do": …}, {"use": "<template>", "with": {…}}.
  • Icons: lucide:<name>[#rrggbb].

An integration can bring actions that bindings run directly (Integration in the action editors), instead of a command written into each binding:

"actions": [{ "id": "scene", "name": "Switch scene", "os": ["linux", "windows"],
"params": [{ "key": "scene", "label": "Scene", "kind": "choice", "source": { "server": "obs", "query": "obs-cmd scene list --json" } }],
"program": "obs-cmd", "args": ["scene", "switch", "%{scene}"],
"target": "pointer", "response": { "success": "ok", "error": "message" } }]
  • program is a literal executable (looked up in PATH), each args entry one argument: no shell, so no |q (refused). Params are the templates’ ones; name may be %{t.key}.
  • An entry that is only %{key} of a multiple choice gives one argument per option chosen (none when nothing is); inside a text (--ids=%{key}) they are joined by spaces.
  • Bindings keep a reference — {"integration_action": {"integration": "obs", "action": "scene", "values": {"scene": "Live"}}} — so updating the integration updates every binding; a disabled or missing integration leaves them saved but unavailable.
  • A chosen value is checked against the choices each time the action runs; a source’s answer is reused for a minute while it holds the values.
  • target: pointer (default: the window under the pointer gets the focus first) or focus (left as is). response: stdout is a JSON object whose boolean field tells success.
  • Runs in order, outside the input loop, 3 s and 16 KiB of output at most, with the security settings — unless "detach": true: the program is started and left running (an app, a terminal), with no time limit and no response.
  • Lists, overlay hints and wheel chips show the values chosen (their labels), else the action’s name. They count in the risk as commands.
{ "id": "browser", "name": "Browser", "class": "firefox|chromium", "trigger": "mouse_right", "version": 1,
"gestures": [{ "name": "back", "pattern": [[-1, 0]], "key_combo": "alt+Left", "key_combo_mac": "cmd+[" }],
"chords": [], "hubs": [] }

Each binding becomes a template; raising version offers Update to who turned it on. Actions may carry per_os (see Actions).

See Themes: overlay keys, tokens, a palette and palette_files.

virgul state-server runs each query as a shell command and answers its output (watched: again every --every). Write queries that print JSON: {"text": …, "value": 0.4, "on": true, "color": "#…"} for a state, a list of bubbles for a dynamic branch.

The installer shows what your integration runs (risk levels). Keep it honest and minimal: the fewer background programs, the fewer questions.

  1. Put the manifest in the repository (internal/integration/builtin/ for built-ins, generated by gen_tools.py for the command line tool ones).
  2. Add an entry to integrations/index.json with the same version; raise both on each change.
  3. Run go test ./internal/integration — it builds every template in every language and checks every command with sh -n and every icon.