Overview
The pub/sub commands provide a messaging system for communication between Yazi instances and external tools. Unlikeemit which sends commands, pub/sub is designed for custom events and data exchange.
pub
Publish a message to the current Yazi instance.Synopsis
Arguments
string
required
Kind of message to publish.This is a custom identifier for your message type. It should be unique and descriptive.
Options
string
Send the message with a string body.The string will be JSON-encoded.
string
Send the message with a JSON body.The JSON string should be valid JSON and will be sent as-is.
string[]
Send the message as a list of strings.Multiple values can be provided, and they will be sent as a JSON array.
Examples
pub-to
Publish a message to a specific Yazi instance.Synopsis
Arguments
number
required
Receiver instance ID.The client ID of the target Yazi instance.
string
required
Kind of message to publish.
Options
Same aspub command:
--str- String message body--json- JSON message body--list- List of strings
Examples
sub
Subscribe to messages from all remote instances.Synopsis
Arguments
string
required
Kinds of messages to subscribe to, separated by commas.Multiple message kinds can be specified to listen for different event types.
Behavior
- Subscribes to the specified message kinds
- Prints received messages to stdout
- Runs until interrupted with Ctrl+C
- Listens for messages from all remote Yazi instances
Examples
Output Format
Messages are printed to stdout as they arrive. The exact format depends on the message body:Use Cases
File Watching Integration
Build System Integration
Inter-Instance Communication
Custom Event Monitoring
Plugin Communication
Status Broadcasting
Message Body Types
Pub/sub supports three body types:String Body (--str)
Best for simple text messages. The string is JSON-encoded automatically:
JSON Body (--json)
Best for structured data. Must be valid JSON:
List Body (--list)
Best for multiple items. Creates a JSON array:
Empty Body
If no body options are specified, an empty message is sent:Error Handling
Commands exit with status code1 if:
- Cannot connect to the target instance
- Invalid instance ID (for
pub-to) - Message fails to send
- Invalid JSON in
--jsonoption
Environment Variables
string
Current Yazi instance ID.Used by
pub to determine the target instance. Set automatically by Yazi.string
Alternative to
YAZI_ID.