Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/sxyazi/yazi/llms.txt

Use this file to discover all available pages before exploring further.

Overview

The emit and emit-to commands allow you to send commands to running Yazi instances. This enables automation, remote control, and integration with other tools.

emit

Emit a command to be executed by the current Yazi instance.

Synopsis

ya emit <NAME> [ARGS]...

Arguments

NAME
string
required
Name of the command to execute.This should be a valid Yazi command name (e.g., cd, refresh, search, select).
ARGS
string[]
Arguments to pass to the command.Arguments can include hyphens and are passed directly to the command handler.
# Command with arguments
ya emit cd --path="/home/user/Downloads"

# Multiple arguments
ya emit select --items=file1.txt --items=file2.txt

Examples

# Navigate to parent directory
ya emit leave

# Navigate to a specific path
ya emit cd --path="/etc"

# Refresh the current directory
ya emit refresh

# Toggle selection of current item
ya emit toggle

# Search for files matching pattern
ya emit search --pattern="*.conf"

# Quit Yazi
ya emit quit

Use Cases

Automation Scripts

#!/bin/bash
# Automated file organization

ya emit cd --path="$HOME/Downloads"
ya emit search --pattern="*.pdf"
ya emit select-all
ya emit copy
ya emit cd --path="$HOME/Documents/PDFs"
ya emit paste

Integration with Other Tools

# Trigger Yazi actions from external scripts
if [ -f "important.txt" ]; then
    ya emit reveal --path="important.txt"
fi

Shell Functions

# Quick navigation helper
function ycd() {
    ya emit cd --path="$1"
}

ycd /var/log

emit-to

Emit a command to be executed by a specific Yazi instance.

Synopsis

ya emit-to <RECEIVER> <NAME> [ARGS]...

Arguments

RECEIVER
number
required
Receiver instance ID.This is the client ID of the target Yazi instance (specified via --client-id when starting Yazi).
ya emit-to 12345 refresh
NAME
string
required
Name of the command to execute.
ARGS
string[]
Arguments to pass to the command.

Examples

# Send refresh command to instance 1000
ya emit-to 1000 refresh

# Navigate a specific instance
ya emit-to 1000 cd --path="/var/log"

# Control multiple instances
ya emit-to 1000 cd --path="/home/user"
ya emit-to 2000 cd --path="/etc"
ya emit-to 3000 cd --path="/var"

# Quit specific instance
ya emit-to 1000 quit

Use Cases

Multi-Instance Orchestration

#!/bin/bash
# Synchronize multiple Yazi instances to same directory

TARGET_DIR="/home/user/project"

for instance in 1000 2000 3000; do
    ya emit-to $instance cd --path="$TARGET_DIR"
done

Remote Control

# Control Yazi instance from another terminal
INSTANCE_ID=12345

# Navigate to directory
ya emit-to $INSTANCE_ID cd --path="$HOME/Downloads"

# Trigger refresh
ya emit-to $INSTANCE_ID refresh

Build System Integration

# Refresh file view after build completes
make build
if [ $? -eq 0 ]; then
    ya emit-to $YAZI_ID refresh
    echo "Build succeeded, view refreshed"
fi

Command Serialization

Commands are serialized as JSON arrays with the command name followed by arguments:
["cd", "--path=/home/user"]
Arguments that contain special characters are properly encoded to handle:
  • Unicode characters
  • Spaces and special shell characters
  • Binary data (converted to byte arrays)

Error Handling

Both commands will exit with status code 1 and print an error message if:
  • The target instance is not reachable
  • The instance ID is invalid (for emit-to)
  • The command fails to serialize
  • DDS communication fails
Example error:
ya emit-to 99999 refresh
# Cannot emit command: Connection refused

Environment Variables

YAZI_ID
string
Current Yazi instance ID. Set automatically by Yazi.Used by emit to determine the target instance.
YAZI_PID
string
Alternative to YAZI_ID. Contains the instance process ID.

See Also

  • ya - Main CLI utility
  • pub-sub - Pub/sub messaging for custom events
  • yazi - Start Yazi with specific client ID

Build docs developers (and LLMs) love