26 lines
683 B
Bash
26 lines
683 B
Bash
#!/bin/sh
|
|
# tmux clipboard helper - works locally and over SSH/mosh
|
|
|
|
set -eu
|
|
|
|
# Read from stdin
|
|
buf=$(cat)
|
|
|
|
# Try methods in order of preference
|
|
copy_backend_remote_tunnel_port=$(tmux show-option -gvq "@copy_backend_remote_tunnel_port" 2>/dev/null || echo "")
|
|
|
|
# Method 1: Use pbcopy if available (local macOS)
|
|
if command -v pbcopy >/dev/null 2>&1; then
|
|
printf "%s" "$buf" | pbcopy
|
|
# Method 2: OSC 52 (for mosh/ssh)
|
|
elif [ -n "${TMUX:-}" ]; then
|
|
# Get the tmux tty
|
|
tmux_tty=$(tmux display-message -p '#{client_tty}')
|
|
|
|
# Encode in base64
|
|
encoded=$(printf "%s" "$buf" | base64 | tr -d '\n')
|
|
|
|
# Send OSC 52 sequence
|
|
printf "\033]52;c;%s\a" "$encoded" > "$tmux_tty"
|
|
fi
|