Skip to content

Actions

init.lua registers one or more actions with waydir.register. Waydir stores the contribution metadata, then calls the matching action's run(ctx) function when the user invokes it.

Register an action

lua
waydir.register({
  id = "to_webp",
  title = "Convert to WebP",
  menu = "context",
  icon = "file-image",
  when = { extensions = { "png", "jpg", "jpeg" }, min = 1 },
  shortcut = "ctrl+shift+w",
  run = function(ctx)
    for _, path in ipairs(ctx.paths) do
      waydir.run_task({
        title = "Convert " .. path,
        cmd = "cwebp",
        args = { path, "-o", path:gsub("%.%w+$", ".webp") },
      })
    end
  end,
})

Contribution fields

FieldMeaning
idAction id inside this plugin. The full host id becomes plugin:<plugin-id>:<action-id>.
titleLabel shown in menus, toolbar tooltip, and keybindings.
menucontext by default, or menubar, or toolbar.
whereFor context actions: { "selection" }, { "background" }, or both.
groupContext submenu label. Actions sharing a group are nested together.
iconBundled .svg/.png path or a named builtin icon.
shortcutChord such as ctrl+alt+n, alt+f5, or shift+?.
settingsOptional user-editable settings schema.
whenOptional selection filter.
runFunction called when the action is invoked.

Invocation context

FieldMeaning
ctx.pathsSelected paths. Empty on background and toolbar actions.
ctx.countNumber of selected paths.
ctx.dirCurrent folder.
ctx.plugin_dirThe plugin folder, useful for bundled scripts or assets.
ctx.settingsSchema defaults overlaid with saved user values.
ctx.formDialog results after a waydir.dialog round-trip.

when filters

Selection context actions are visible only when every supplied condition matches.

lua
when = {
  types = { "file" },
  extensions = { "png", "jpg" },
  min = 1,
  max = 10,
  in_archive = false,
}
FieldMeaning
types{ "file" }, { "folder" }, or both.
extensionsFile extensions without a dot. Matching is lowercase. Folders do not match extension filters.
minMinimum selected item count. Defaults to 1.
maxMaximum selected item count.
in_archiveUse false to hide inside archives or true to show only inside archives.

Omit when entirely to show the action for any non-empty selection.

Shortcut parsing

Supported modifier names:

  • ctrl, control, cmd, command, meta, super
  • shift
  • alt, option

Supported keys include letters, digits, f1 through f12, arrows, space, enter, tab, escape, backspace, delete, home, end, pageup, pagedown, comma, period, and slash.

Waydir ignores plugin shortcuts that cannot be parsed, conflict with a built-in shortcut, or conflict with an earlier plugin shortcut.

MIT licensed. Open source.