171 lines · 3.8 KB · executable
#!/usr/bin/env bash
set -euo pipefail

# Send commands, keys, bytes, or pasted text to a zellij pane.
#
# Usage:
#   zellij_send.sh [options] <session> [pane] <text...>
#   zellij_send.sh [options] <session> [pane] -- <text...>
#
# Pane formats (default: focused terminal pane, else first terminal pane):
#   terminal_1   → full pane id
#   3            → shorthand for terminal_3
#   plugin_2     → plugin pane
# The pane argument is optional; it is only recognized if it matches a pane
# id pattern. Use `--` to force everything after it to be treated as text.
#
# Options:
#   -e, --enter        Send Enter after the text (default)
#   -n, --no-enter     Do not send Enter after the text
#   -k, --keys         Treat arguments as key names ("Ctrl c", "Esc", "Up")
#   -b, --bytes        Treat arguments as raw byte values (write action).
#                      In bytes mode only full pane ids are recognized.
#   -P, --paste        Paste text via bracketed paste (safe for multiline,
#                      never auto-sends Enter)
#   -d, --delay SEC    Wait SEC seconds before sending
#   -r, --read-back    Capture and print pane output after sending (0.3s delay)
#   -w, --wait SEC     Wait SEC seconds before read-back (implies --read-back)
#   -h, --help         Show this help

usage() {
	sed -n '4,/^$/p' "$0" | sed 's/^# \?//' >&2
	exit 1
}

ENTER=true
KEYS=false
BYTES=false
PASTE=false
DELAY=0
READBACK=false