-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmux-send
More file actions
executable file
·55 lines (50 loc) · 1.87 KB
/
Copy pathtmux-send
File metadata and controls
executable file
·55 lines (50 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env bash
# Send text + Enter to a tmux target.
# Usage: tmux-send [--no-prefix] <target> <text...>
# Uses set-buffer/paste-buffer for reliable multi-line delivery; named buffer avoids concurrent-send collisions.
# NOTE: sending while an agent is mid-run (still processing) may cause odd behaviour — not fully tested.
PREFIX_MODE=1
if [ "${1:-}" = "--no-prefix" ]; then
PREFIX_MODE=0
shift
fi
if [ -z "${1:-}" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Usage: tmux-send [--no-prefix] <target> <text...>"
echo ""
echo "Send literal text plus Enter to a tmux pane."
echo ""
echo "Arguments:"
echo " --no-prefix Do not prepend sender identity when called from inside tmux"
echo " target tmux session, window, or pane target"
echo " Examples: mysession, mysession:0, mysession:0.0"
echo " Bare session names default to :0.0"
echo " text Text to send (joined with spaces)"
echo ""
echo "Examples:"
echo " tmux-send claude_myproject 'Hello agent'"
echo " tmux-send myproject:0.1 'ls -la'"
exit 0
fi
TARGET="$1"
# Default to :0.0 (First window, first pane) if no pane specified in target string
if [[ "$TARGET" != *:*.* ]]; then
# If target is just a session name (no colon), append :0.0
if [[ "$TARGET" != *:* ]]; then
TARGET="${TARGET}:0.0"
# If target is session:window (has colon but no dot), append .0
elif [[ "$TARGET" != *.* ]]; then
TARGET="${TARGET}.0"
fi
fi
shift
MSG="$*"
if [ "$PREFIX_MODE" -eq 1 ] && [ -n "$TMUX" ]; then
SENDER=$(tmux display-message -p '#S:#{window_index}.#{pane_index}')
MSG="${SENDER}: ${MSG}"
fi
BUF="nudge-$$-$RANDOM"
tmux set-buffer -b "$BUF" -- "$MSG"
tmux paste-buffer -b "$BUF" -p -t "$TARGET"
sleep "${TMUX_SEND_ENTER_DELAY:-0.1}"
tmux send-keys -t "$TARGET" C-m
tmux delete-buffer -b "$BUF" 2>/dev/null