Skip to main content
The ps namespace provides a publish/subscribe messaging system for communication between plugins and Yazi components.

Overview

The PubSub system allows plugins to:
  • Subscribe to events from Yazi (DDS events)
  • Publish custom events to other plugins
  • Communicate between plugin instances
  • React to system events

Subscription

ps.sub(kind, callback)

Subscribe to a local event.
string
required
Event kind/name to subscribe to
function
required
Callback function to handle events
Calling ps.sub() twice for the same event kind will error. Each event can only have one subscriber per plugin.

ps.sub_remote(kind, callback)

Subscribe to a remote event (from other Yazi instances or DDS).
string
required
Event kind to subscribe to
function
required
Callback function
As of #3638, ps.sub() can be used directly in init.lua without requiring a plugin.

Publishing

ps.pub(kind, value)

Publish an event locally.
string
required
Event kind
any
required
Event data (must be serializable)

ps.pub_to(receiver, kind, value)

Publish an event to a specific receiver.
Id
required
Receiver ID
string
required
Event kind
any
required
Event data

Unsubscription

ps.unsub(kind)

Unsubscribe from a local event.
string
required
Event kind to unsubscribe from
bool
True if was subscribed, false otherwise

ps.unsub_remote(kind)

Unsubscribe from a remote event.
string
required
Event kind to unsubscribe from
bool
True if was subscribed, false otherwise

DDS Events

Yazi emits various DDS (Data Distribution Service) events that plugins can subscribe to:

File Events

  • cd - Directory changed
  • duplicate - Files copied (#3456)
  • download - Remote files downloaded (#3687)

UI Events

  • ind-app-title - Customize app title (#3684)
  • ind-which-activate - Change which-key behavior (#3608)
  • ind-sort - Change sorting in Lua (#3391)

Key Events

  • key-* - Allow changing or canceling key events (#3005, #3037)
  • key-sort - Sorting key events (#3391)

System Events

  • relay-notify-push - Customize notification handler (#3642)
  • hey - Fires when static messages are restored from persistence (#3725)

Yank Events

  • @yank - Files yanked (copied/cut)

Examples

Subscribe to Directory Changes

Custom Event Communication

DDS Event Bridge (from preset)

The dds.lua preset plugin bridges DDS events to Yazi actions:

Clean Up Subscriptions

Best Practices

  1. Subscribe early - Set up subscriptions in init.lua or plugin setup function
  2. Handle errors - Wrap callback logic in pcall to prevent crashes
  3. Unsubscribe - Clean up subscriptions when no longer needed
  4. Serialize data - Ensure published data is JSON-serializable
  5. Avoid loops - Be careful not to create event loops (A publishes → B subscribes and publishes → A subscribes…)

See Also