Skip to main content

Script commands

Your Lua plugin can register commands that act like the built-ins: bindable to a chord in Settings, listed in the command palette, placeable in the terminal's context menu. This plugins/uptime.lua

local dropterm = require('dropterm')

dropterm.command('paste-uptime', 'Paste system uptime into the pane', function(p)
dropterm.send_text(io.popen('uptime'):read())
end)

gives Settings a paste-uptime row. Bind it, press the chord, and the uptime lands in the focused pane as if you typed it. The plugins page covers the runtime - the lazy host, hot reload, the one-second cap - and the trust model: a plugin is your own config executing as you, complete standard library, no sandbox.

Register a command​

The call is dropterm.command(name, description, handler).

  • The name is a slug: lowercase letters, digits, hyphens, at most 64 characters. It is the command's identity for keeps - the keybindings file stores its chord under script/<name> (keybindings). Anything else is refused with one dropterm: log line. The call does not raise.
  • Registering a name again replaces the earlier command - its description and handler - with one log line.
  • Settings shows one row per live command under Script commands. Load or reload the script and the rows follow. A command that stops registering loses its row, and its stored chord stays in the keybinds file, inert - nothing fires it until the command registers again. Deleting the script and reloading is the same.

Bind a chord​

Bind in Settings, the same capture as a built-in row: click the row's binding chip, press the chord. Escape cancels. A chord another row holds is refused, the holder named - your script's rows count like any other. A command starts unbound: only you can give it a chord, and scripts can't claim one themselves. The binding persists under script/<name> and re-applies at every launch.

Run a command​

Four ways in:

  • A bound chord - press it in the pane.
  • The palette - every live command sits in the palette's Script commands section, bound or not.
  • The context menu - a manifest's menu rows place declared commands at the pointer. A pick runs the command through the same dispatch, and which rows show is your say through context_menu_rows (configuration).
  • A tab's own right-click menu - a manifest's tab-menu rows stand on every tab under one Plugins entry. A pick runs the command on the clicked tab, active or not, and nothing activates it - through the same dispatch, a lazy plugin loading for it the way a chord press does.

All four dispatch the same: fire-and-forget - the handler runs under the same one-second cap as any plugin call (plugins) - and nothing waits on it. A chord run's handler receives { tab }, the id of the pane the chord landed in: the same opaque number the terminal events carry. A tab-menu run receives the chord-run keys, its tab the clicked tab's id. A menu run receives those keys plus three more, each a string or nil: selection (the selected text), word (the run of non-blank characters around the clicked cell), cwd (the pane's working directory). A handler that raises costs one log line, and the terminal and every other command are unaffected. When the tab the command ran on wears a label, the ctx carries it as label, a { text, color } table, on chord, palette, terminal-menu, and tab-menu runs alike; a tab with no label has no key. A press on a command that is no longer registered - or never was - dispatches to nobody, with one log line.

send_text - write into the pane​

dropterm.send_text(text) sends keystrokes to a pane: raw input on the typed-key path, no bracketed-paste wrapping, no newline handling - include \n yourself when you want Enter. Any plugin handler can call it, not only command handlers: an event handler or a chip's band view too. Where the write lands follows the ctx the handler holds:

  • from a command handler, the pane the command ran on - for a tab-menu row's pick, the clicked tab, active or not;
  • from a terminal-event handler, the event's own tab;
  • from anywhere with no tab in ctx - a load-time call, a slot-event handler - the call drops with one log line, nothing written.

The call returns at once and the write lands on the next UI tick. A tab whose pane exited since the dispatch drops the write with one log line, nothing written. No return value. One ordering guarantee: sends land in the order they were made. The rest of the plugin API lives on the plugins page - dropterm.tabs and friends (bands).